99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

模塊

2018-06-26 18:41 更新

模塊是 Notadd 的功能實(shí)體,是區(qū)別于 notadd/framework 來(lái)說(shuō)的,notadd/framework 僅是承載 Notadd 體系的邏輯實(shí)現(xiàn),并沒(méi)有包含功能性代碼。

目錄結(jié)構(gòu)

模塊位于目錄 modules 下,每個(gè)模塊在一個(gè)獨(dú)立的文件夾內(nèi),模塊內(nèi)部的目錄結(jié)構(gòu)如下:

module 模塊目錄
-resources 資源目錄
--translations 翻譯文件目錄
--views 視圖目錄
-src 源碼目錄
--ModuleServiceProvider.php 模塊服務(wù)提供者定義文件
-composer.json Composer 配置文件

Resources

Resources 目錄是 Module 的資源類(lèi)文件放置的目錄,包含如下幾個(gè)類(lèi)型目錄:

  • assets
  • translations
  • views

Assets

  • assets 目錄為前端相關(guān)資源或項(xiàng)目的放置目錄。

Translations

  • translations 目錄為多語(yǔ)言資源文件的放置目錄。

Views

  • views 目錄為視圖資源文件的放置目錄。

ModuleServiceProvider

-ModuleServiceProvider 是 Module 的模塊入口文件,也 Module 的所有功能容器示例注冊(cè)、路由注入等一系列功能注冊(cè)及組件啟動(dòng)的服務(wù)提供者。

完整示例

namespace Notadd\Content;


use Illuminate\Events\Dispatcher;
use Illuminate\Support\ServiceProvider;
use Notadd\Content\Events\RegisterArticleTemplate;
use Notadd\Content\Events\RegisterArticleType;
use Notadd\Content\Events\RegisterCategoryTemplate;
use Notadd\Content\Events\RegisterCategoryType;
use Notadd\Content\Events\RegisterPageTemplate;
use Notadd\Content\Events\RegisterPageType;
use Notadd\Content\Listeners\CsrfTokenRegister;
use Notadd\Content\Listeners\RouteRegister;
use Notadd\Content\Managers\ArticleManager;
use Notadd\Content\Managers\CategoryManager;
use Notadd\Content\Managers\PageManager;


/**
 * Class Module.
 */
class ModuleServiceProvider extends ServiceProvider
{
    /**
     * Boot service provider.
     */
    public function boot()
    {
        $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class);
        $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class);
        $this->loadMigrationsFrom(realpath(__DIR__ . '/../databases/migrations'));
        $this->loadTranslationsFrom(realpath(__DIR__ . '/../resources/translations'), 'content');
    }


    /**
     * Register services.
     */
    public function register()
    {
        $this->app->alias('article.manager', ArticleManager::class);
        $this->app->alias('category.manager', CategoryManager::class);
        $this->app->alias('page.manager', PageManager::class);
        $this->app->singleton('article.manager', function ($app) {
            $manager = new ArticleManager($app, $app['events']);
            $this->app->make(Dispatcher::class)->fire(new RegisterArticleTemplate($app, $manager));
            $this->app->make(Dispatcher::class)->fire(new RegisterArticleType($app, $manager));


            return $manager;
        });
        $this->app->singleton('category.manager', function ($app) {
            $manager = new CategoryManager($app, $app['events']);
            $this->app->make(Dispatcher::class)->fire(new RegisterCategoryTemplate($app, $manager));
            $this->app->make(Dispatcher::class)->fire(new RegisterCategoryType($app, $manager));


            return $manager;
        });
        $this->app->singleton('page.manager', function ($app) {
            $manager = new PageManager($app, $app['events']);
            $this->app->make(Dispatcher::class)->fire(new RegisterPageTemplate($app, $manager));
            $this->app->make(Dispatcher::class)->fire(new RegisterPageType($app, $manager));


            return $manager;
        });
    }
}

ModuleServiceProvider

ModuleServiceProvider 是 Module 的模塊入口文件,也 Module 的所有功能容器示例注冊(cè)、路由注入等一系列功能注冊(cè)及組件啟動(dòng)的服務(wù)提供者。

完整示例

namespace Notadd\Content;


use Illuminate\Events\Dispatcher;
use Illuminate\Support\ServiceProvider;
use Notadd\Content\Events\RegisterArticleTemplate;
use Notadd\Content\Events\RegisterArticleType;
use Notadd\Content\Events\RegisterCategoryTemplate;
use Notadd\Content\Events\RegisterCategoryType;
use Notadd\Content\Events\RegisterPageTemplate;
use Notadd\Content\Events\RegisterPageType;
use Notadd\Content\Listeners\CsrfTokenRegister;
use Notadd\Content\Listeners\RouteRegister;
use Notadd\Content\Managers\ArticleManager;
use Notadd\Content\Managers\CategoryManager;
use Notadd\Content\Managers\PageManager;


/**
 * Class Module.
 */
class ModuleServiceProvider extends ServiceProvider
{
    /**
     * Boot service provider.
     */
    public function boot()
    {
        $this->app->make(Dispatcher::class)->subscribe(CsrfTokenRegister::class);
        $this->app->make(Dispatcher::class)->subscribe(RouteRegister::class);
        $this->loadMigrationsFrom(realpath(__DIR__ . '/../databases/migrations'));
        $this->loadTranslationsFrom(realpath(__DIR__ . '/../resources/translations'), 'content');
    }


    /**
     * Register services.
     */
    public function register()
    {
        $this->app->alias('article.manager', ArticleManager::class);
        $this->app->alias('category.manager', CategoryManager::class);
        $this->app->alias('page.manager', PageManager::class);
        $this->app->singleton('article.manager', function ($app) {
            $manager = new ArticleManager($app, $app['events']);
            $this->app->make(Dispatcher::class)->fire(new RegisterArticleTemplate($app, $manager));
            $this->app->make(Dispatcher::class)->fire(new RegisterArticleType($app, $manager));


            return $manager;
        });
        $this->app->singleton('category.manager', function ($app) {
            $manager = new CategoryManager($app, $app['events']);
            $this->app->make(Dispatcher::class)->fire(new RegisterCategoryTemplate($app, $manager));
            $this->app->make(Dispatcher::class)->fire(new RegisterCategoryType($app, $manager));


            return $manager;
        });
        $this->app->singleton('page.manager', function ($app) {
            $manager = new PageManager($app, $app['events']);
            $this->app->make(Dispatcher::class)->fire(new RegisterPageTemplate($app, $manager));
            $this->app->make(Dispatcher::class)->fire(new RegisterPageType($app, $manager));


            return $manager;
        });
    }
}

Composer

通過(guò)對(duì) Composer 的自定義,可以實(shí)現(xiàn) Notadd 風(fēng)格的目錄結(jié)構(gòu)。

Type

配置 type 屬性為 notadd-module,會(huì)告訴 Composer Installer 將該 Package 安裝到目錄 modules 下,而非默認(rèn)目錄 vendor 下。

Require

添加 notadd/installers 的 Package,才能調(diào)整 Composer 對(duì)該類(lèi)型 Package 的默認(rèn)處理邏輯,實(shí)現(xiàn)重定向安裝目錄的特性。 介于,模塊的安裝方式有兩種,一種方式是:將 Composer Package 寫(xiě)入程序根目錄的 composer.json 文件,另一種方法是,單獨(dú)初始化模塊 Package,并以文件夾的形式放到 modules 目錄,因此,包 notadd/installers 應(yīng)放置在 require-dev 中。

完整示例

{
    "name": "notadd/content",
    "description": "Notadd's Content Module.",
    "keywords": [
        "notadd",
        "cms",
        "framework",
        "content"
    ],
    "homepage": "https://notadd.com",
    "license": "Apache-2.0",
    "type": "notadd-module",
    "authors": [
        {
            "name": "twilroad",
            "email": "heshudong@ibenchu.com"
        }
    ],
    "require": {
        "php": ">=7.0"
    },
    "require-dev": {
        "notadd/installers": "0.5.*"
    },
    "autoload": {
        "psr-4": {
            "Notadd\\Content\\": "src/"
        }
    }
}
以上內(nèi)容是否對(duì)您有幫助:
在線(xiàn)筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)