Laravel 모듈화

Created by 구준호

나에게 모듈화가 필요한 이유

모듈화의 장점

  • 쉬운 교체
  • 재사용
  • 빠른 개발

프리랜서가 모듈을 갖게되면?

  • 영업 툴
  • 기획, 커뮤니케이션 편리

Laravel에서 Slack 사용하기

구글링

"laravel slack"

https://github.com/maknz/slack

다운로드


composer require maknz/slack

Config - Service Provider


'providers' => [
    ...
    'Maknz\Slack\SlackServiceProvider',
],

Service Provider

Service providers are the central place to configure your application.

Slack Service Provider

Slack Config

Publish


php artisan vendor:publish

사용


Slack::send('Hello world!');

Laravel의 모듈화

Service Providers

Github

Github

Packagist

Service Provider

Config

TranslationServiceProvider

TranslationServiceProvider



namespace Illuminate\Translation;

use Illuminate\Support\ServiceProvider;

class TranslationServiceProvider extends ServiceProvider
{
    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = true;

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->registerLoader();

        $this->app->singleton('translator', function ($app) {
            $loader = $app['translation.loader'];

            // When registering the translator component, we'll need to set the default
            // locale as well as the fallback locale. So, we'll grab the application
            // configuration so we can easily get both of these values from there.
            $locale = $app['config']['app.locale'];
            $trans = new Translator($loader, $locale);
            $trans->setFallback($app['config']['app.fallback_locale']);
            return $trans;
        });
    }

    /**
     * Register the translation line loader.
     *
     * @return void
     */
    protected function registerLoader()
    {
        $this->app->singleton('translation.loader', function ($app) {
            return new FileLoader($app['files'], $app['path.lang']);
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return ['translator', 'translation.loader'];
    }
}

구성요소

  • Routes
  • Views
  • Translations
  • Configuration
  • Public Assets
  • Overriding
  • Publishing

Laravel 팀의 모듈 개발방법

laravel/laravel

laravel/laravel composer.json

laravel/framework

Components ?

Components ?

Build

적용

Framework

Modules 통합 프로젝트

다른 Modules

Build

Admin

Wiki

Blog

결론

  • Laravel 역시 composer 를 통한 모듈화가 가능하다
  • Frame 이 제공되므로 좀 더 다양한 시도가 가능하다
  • 버전관리, 배포를 laravel 만큼 잘 할 수 있다

One more thing...

Node.JS에서 배우기

Node.JS에서 배우기

“Fixing a bug in a snippet means updating one module instead of manually fixing all the instances where the snippet is used.”

함께 일하기

PHP-FIG

THE END