2017 © Pedro Peláez
 

framework-extension laravel-addomnipot

Addon system for Laravel.

image

jumilla/laravel-addomnipot

Addon system for Laravel.

  • Tuesday, September 19, 2017
  • by jumilla
  • Repository
  • 4 Watchers
  • 4 Stars
  • 839 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 36 Versions
  • 2 % Grown

The README.md

Laravel Addomnipot

Build Status Quality Score Code Coverage Latest Stable Version Total Downloads Software License, (*1)

日本語ドキュメント - Japanese, (*2)

Features

  • Additional add-on features, (*3)

    • It is a package feature in the application. You can use the image to replicate the directory structure of Laravel 5.
    • By default, it will be placed under the 'addons' directory.
    • You can make one have its own name space (PSR-4) to add-on.
    • It can serve as a package of Laravel 5. Valid namespace notation {addon-name}:: can be used 'lang', 'view'. Also can use 'config'.
    • Only additional add-on to copy the directory. You do not need to add code to the configuration file, such as 'config/app.php'.
    • 9 types of stationery and offers 2 types of sample. Can be generated by artisan command php artisan make:addon.
  • Solution of a facade problem in the namespace, (*4)

    • A facade can be used in the class with a name space under the app directory. (A backslash and a use declaration, unnecessary)
    • A facade can also be handled by the same description method from the inside in add-on name space.

How to install

[A] Download the Laravel stationery project

Note: Pacakge Discovery supported., (*5)

It is a way to use a model project already to incorporate the Laravel Extension Pack., (*6)

In addition to the Laravel Addomnipot of add-on features, and to the Laravel Versionia of semantic version-based migration feature, you can also use source code generator corresponding to the add-on., (*7)

composer create-project laravel-plus/laravel5 <project-name>

[B] Install the laravel-plus/extension to an existing project.

Note: Pacakge Discovery supported., (*8)

It is a way to use Laravel Extension Pack., (*9)

In addition to the Laravel Addomnipot of add-on features, and to the Laravel Versionia of semantic version-based migration feature, you can also use source code generator corresponding to the add-on., (*10)

For more information, please refer to the Laravel Extension Pack of the document., (*11)

[C] Install the jumilla/laravel-addomnipot to an existing project.

Note: Pacakge Discovery supported., (*12)

It is a way to incorporate the only Laravel Addomnipot of add-on features., (*13)

1. Add the package jumilla/laravel-addomnipot use Composer.

Use composer., (*14)

composer require jumilla/laravel-addomnipot

2. Add the service provider.

Edit file config/app.php., (*15)

    'providers' => [
        Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
        ...
        // Add the folloing line.
        Jumilla\Addomnipot\Laravel\ServiceProvider::class,
    ],

Check for running

Add-on wiki is made as a example., (*16)

php artisan make:addon wiki sample:ui

Please confirm the routing setting., (*17)

php artisan route:list

A local server is started and accesses http://localhost:8000/addons/wiki by a browser. When a package name is indicated, it's success., (*18)

php artisan serve

Commands

addon:list

List addons., (*19)

php artisan addon:list

When addons directory file don't exist, it's made., (*20)

addon:status

Can check the status of addons., (*21)

php artisan addon:status

When addons directory file don't exist, it's made., (*22)

addon:name

A file in the add-on is scanned and the PHP namespace is changed., (*23)

php artisan addon:name blog Wonderful/Blog

When you'd like to confirm the scanned file, please designate -v option., (*24)

php artisan addon:name blog Wonderful/Blog -v

addon:remove

An add-on is eliminated., (*25)

php artisan addon:remove blog;

addons/blog A directory is just eliminated., (*26)

make:addon

An add-on is made. I add on the next command blog is generated as PHP name spatial Blog using a form of library-type, blog-app is generated as PHP name spatial BlogApp using a form of ui-type., (*27)

php artisan make:addon blog library
php artisan make:addon blog-app ui

A skeleton can be chosen from 10 kinds., (*28)

  • minimum - Minimum structure.
  • simple - The simple structure with the directory views and the file Http/route.php.
  • asset - Minimum structure.
  • library - The composition to which a PHP range and a database are offered.
  • api - The structure for Web API.
  • ui - The structure for Web UI.
  • ui-sample - Example of a Web UI.
  • debug - The add-on in which program testing facility is put. Service provider registration of 'debug-bar' is also included.
  • generator - Customized for stub files.
  • laravel5 - The directory structure of Laravel 5.
  • laravel5-auth - The authentication sample included in Laravel 5.

When not designating a form by a command argument, it can be chosen by an interactive mode., (*29)

php artisan make:addon blog

PHP namespace can designate --namespace by an option. Please use \\ or / for a namespace separate., (*30)

php artisan make:addon blog --namespace App\\Blog
php artisan make:addon blog --namespace App/Blog

Helper functions

addon($name = null)

Get the add-on by name., (*31)

$addon = addon('blog');

If omit the name, it returns the add-on that contains the calling class. This is equivalent to a addon(addon_name())., (*32)


namespace Blog\Http\Controllers; class BlogController { public function index() { $addon = addon(); // == addon(addon_name()) Assert::same('blog', $addon->name()); } }

LaravelPlus\Extension\Addons\Addon object retrieved by the addon() function, you can access the add-on attributes and resources., (*33)

$addon = addon();
$addon->path();             // {$root}/addons/blog
$addon->relativePath();     // addons/blog
$addon->phpNamespace();     // Blog
$addon->config('page.row_limit', 20);
$addon->trans('emails.title');
$addon->transChoice('emails.title', 2);
$addon->view('layouts.default');
$addon->spec('forms.user_register');

addon_name($class)

Get the add-on name from the class name . The class name must be a fully qualified name that contains the name space. Get the add-on by name., (*34)

$name = addon_name(get_class($this));
$name = addon_name(\Blog\Providers\AddonServiceProvider::class);        // 'blog'

If you omit the argument, returns the name of the add-on contains the caller of the class., (*35)

<?php

namespace Blog\Http\Controllers;

class PostsController
{
    public function index()
    {
        $name = addon_name();       // 'blog'
    }
}

Facade expansion

Facade of Laravel converts the static method call of class to an instance method invocation, and has been achieved by creating an alias for the facade class in the global namespace. For Laravel 5 alias loader does not act only in the global name space , to handle the facade from the name space (such as App) it must put \ to the class name prefix., (*36)

function index()
{
    return \View::make()
}

Or a use declaration is used., (*37)

use View;

...

function index()
{
    return View::make()
}

Laravel Extension has the alias loader which settles a facade in the namespace in the add-on bottom, so a way of Laravel 4.2 formula document mentioning can be used just as it is., (*38)

function index()
{
    return View::make()
}

Bootstrap behavior

  • Require files entry in file addons/{addon-name}/addon.json.
  • Sees namespace entry in file addons/{addon-name}/addon.php and establishes class automatic threading based on PSR-4 agreement to all directories specified as directories.

Author

古川 文生 / Fumio Furukawa (fumio@jumilla.me), (*39)

License

MIT, (*40)

The Versions