PHP code example of yish / generators

1. Go to this page and download the library: Download yish/generators library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yish / generators example snippets

 php

//app.php
'providers' => [
    \Yish\Generators\GeneratorsServiceProvider::class,
],
 bash
$ php artisan make:service UserService
 php

namespace App\Services;

use Yish\Generators\Foundation\Service\Service;

class UserService
{
    protected $repository;

    //
}
 php
all()
create($attributes)
first()
firstBy($column, $value)
find($id)
findBy($column, $value)
get()
getBy($column, $value)
update($id, $attributes)
updateBy($column, $value, $attributes)
destroy($id)
destroyBy($column, $value)
paginate($page = 12)
paginateBy($column, $value, $page = 12)
 bash
$ php artisan make:repository UserRepository
 php

namespace App\Repositories;

use Yish\Generators\Foundation\Repository\Repository;

class UserRepository
{
    protected $model;

    //
}
 php
all($columns = ['*'])
create($attributes)
update($id, array $attributes, array $options = [])
updateBy($column, $value, array $attributes = [], array $options = [])
first($columns = ['*'])
firstBy($column, $value, $columns = ['*'])
find($id, $columns = ['*'])
findBy($column, $value, $columns = ['*'])
get($columns = ['*'])
getBy($column, $value, $columns = ['*'])
destroy($ids)
destroyBy($column, $value)
paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
paginateBy($column, $value, $perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
 bash
$ php artisan make:transformer UserTransformer
 php

namespace Yish\Generators\Foundation\Transform;
interface TransformContract
{
    public function transform($attributes);
}
 php
// $instance => Transformer class.
// $attributes => Need transform data, maybe array or collection etc.
transformer(UserTransformer::class, $data);
 bash
$ php artisan make:formatter UserFormatter
 php


namespace App\Formatters;

use Illuminate\Http\Request;
use Yish\Generators\Foundation\Format\FormatContract;
use Yish\Generators\Foundation\Format\Statusable;

class PostFormatter implements FormatContract
{
    public function format(Request $request, $items = [], $message = '', $status = 200)
    {
        //
    }
}
 php

namespace Yish\Generators\Foundation\Format;
use Illuminate\Http\Request;
interface FormatContract
{
    public function format(Request $request, $items = []);
}
 php
// $request => Must instance of `Illuminate\Http\Request`.
// $instance => Formatter class.
// $items => data.
formatter(request(), UserFormatter::class, $data);
 bash
$ php artisan make:presenter UserPresenter
 php


namespace App\Presenters;

class UserPresenter
{
    //
}
 bash
$ php artisan make:foundation Taggable
 php


namespace App\Foundation;

class Taggable
{
  //
}
 bash
$ php artisan make:transport UserTransport
 php


namespace App\Transports;

class UserTransport
{
  //
}
 bash
$ php artisan make:parser UserParser
 php


namespace App\Parsers;

use Yish\Generators\Foundation\Parser\Parser;

class UserParser extends Parser
{
    public function parse(array $items)
    {
        return parent::parse($items);
    }

    public function keys()
    {
        return [
            'name',
            'ages',
            'location'
        ];
    }
}
 php
$parser = app(UserParser::class)->parse(['Yish', 30, 'Taipei']);
// ['name' => 'Yish', 'ages' => 30, 'location' => 'Taipei'];
 bash
$ php artisan make:response UserResponse
 php

namespace App\Responses;
use Illuminate\Contracts\Support\Responsable;
class UserResponse implements Responsable
{
    public function toResponse($request)
    {
        //
    }
}