承接 alxdorosenco/porto-for-laravel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alxdorosenco/porto-for-laravel

Composer 安装命令:

composer require alxdorosenco/porto-for-laravel

包简介

This package is a solution for easy building and working with Porto pattern structure

README 文档

README

For Laravel [9.x, 8.x, 7.x, 6.x, 5.8, 5.7, 5.6, 5.5] please use the latest [9.0, 8.0, 7.0, 6.0, 5.8, 5.7, 5.6, 5.5] version.

This is a package who gives flexible way to build a structure of the Porto (Software Architectural Pattern) in your Laravel project. You should no longer to migrate a lot of files and folders handle.

This package will do the job for you in some clicks.

Introduction

Laravel is a popular and beautiful PHP framework who helps a lot to make your web applications. But web applications tend to grow and become harder to maintain and optimize. Unfortunately, Laravel, like other frameworks, does not have standard tools that allow you to write flexible, readable and easily maintainable code.

Porto (Software Architectural Pattern) is a brilliant solution for building large applications. This pattern helps you and your team to organize and maintain your code.

You can find more information about Porto by this link: https://github.com/Mahmoudz/Porto

How to install?

  1. First of all you need to install the package:

    composer require alxdorosenco/porto-for-laravel
    
  2. Next, you need to enable installed package in your .env file:

    PORTO_ENABLED=true
    
  3. Next, you can install porto structure using this command:

    php artisan porto:install --container=<Container Name> --container-<Container Type>
    

    You need to put directory path when the Porto structure will be installed or you can confirm installation in the default app/ directory.

    Of course, if you put the custom directory path, you need to set it in the autoload -> psr-4 in the composer.json file.

    You also can add directory name of your first container. For example:

    --container=<Container Name>
    

    This container will be installed in the Containers directory with standard structure. You also can force another container structures like:

    --container-default
    --container-api
    --container-cli
    --container-web
    --container-full
    
  4. Next, you need to put some changes in the bootstrap/app.php file.

    From:

     $app->singleton(
         Illuminate\Contracts\Http\Kernel::class,
         App\Http\Kernel::class
     );
     
     $app->singleton(
         Illuminate\Contracts\Console\Kernel::class,
         App\Console\Kernel::class
     );
     
     $app->singleton(
         Illuminate\Contracts\Debug\ExceptionHandler::class,
         App\Exceptions\Handler::class
     );

    To:

     $app->singleton(
         Illuminate\Contracts\Http\Kernel::class,
         <Porto path name>\Ship\Kernels\HttpKernel::class
     );
     
     $app->singleton(
         Illuminate\Contracts\Console\Kernel::class,
         <Porto path name>\Ship\Kernels\ConsoleKernel::class
     );
     
     $app->singleton(
         Illuminate\Contracts\Debug\ExceptionHandler::class,
         <Porto path name>\Ship\Exceptions\Handler::class
     );
  5. At last, you need to comment or clear Application Service Providers in the file config/app.php. Because you don't need them. The package loads automatically all providers from Ship and Containers

    /*
    * Application Service Providers...
    */
    //App\Providers\AppServiceProvider::class,
    //App\Providers\AuthServiceProvider::class,
    // App\Providers\BroadcastServiceProvider::class,
    //App\Providers\EventServiceProvider::class,
    //App\Providers\RouteServiceProvider::class
  6. That's all. Below you can find the skeleton structure of ship, each type of containers and information about adapted laravel console commands.

Ship structure

This is a skeleton of the installed Ship structure.

Ship
    ├── Abstracts
    │   ├── Broadcasting
    │   │   ├── Channel.php
    │   │   ├── PresenceChannel.php
    │   │   └── PrivateChannel.php
    │   │── Commands
    │	│   └── ConsoleCommand.php
    │   ├── Components
    │	│   └── Component.php
    │   ├── Controllers
    │	│   └── Controller.php
    │   ├── Events
    │	│   └── Event.php
    │   ├── Exceptions
    │	│   └── Handler.php
    │   ├── Factories
    │	│   └── Factory.php
    │   ├── Jobs
    │	│   └── Job.php
    │   ├── Mails
    │	│   ├── Mailables
    │	│   │   ├── Content.php
    │	│   │   └── Envelope.php
    │	│   └── Mailable.php
    │   ├── Middleware
    │   │   ├── Authenticate.php
    │   │   ├── EncryptCookies.php
    │   │   ├── PreventRequestsDuringMaintenance.php
    │   │   ├── TrimStrings.php
    │   │   ├── TrustHosts.php
    │   │   ├── TrustProxies.php
    │   │   ├── ValidateSignature.php
    │   │   └── VerifyCsrfToken.php
    │   ├── Models
    │   │   ├── BaseModel.php
    │   │   ├── UserModel.php
    │   │   ├── Pivot.php
    │   │   ├── MorphPivot.php
    │   │   └── Builder.php
    │   ├── Notifications
    │	│   ├── Messages
    │	│   │   └── MailMessage.php
    │   │   └── Notification.php
    │   ├── Policies
    │	│   └── Policy.php
    │   ├── Providers
    │   │   ├── AuthServiceProvider.php
    │   │   ├── ServiceProvider.php
    │   │   ├── EventServiceProvider.php
    │   │   └── RouteServiceProvider.php
    │   ├── Requests
    │   │   ├── Request.php
    │   │   └── FormRequest.php
    │   ├── Responses
    │   │   ├── Response.php
    │   │   ├── RedirectResponse.php
    │   │   └── JsonResource.php
    │   ├── Resources
    │	│   └── ResourceCollection.php
    │   ├── Seeders
    │	│   └── Seeder.php
    │   ├── Tests
    │	│   └── PhpUnit
    │	│       └── TestCase.php
    │   ├── Translations
    │	│   └── PotentiallyTranslatedString.php
    │   └── Views
    │	    └── Component.php
    ├── Broadcasting
    │   ├── Channel.php
    │   ├── PresenceChannel.php
    │   └── PrivateChannel.php
    ├── Commands
    ├── Configs
    ├── Controllers
    │   └── Controller.php
    ├── Events
    │   └── Event.php 
    ├── Exceptions
    │   └── Handler.php
    ├── Helpers
    │   └── helper.php
    ├── Kernels
    │   ├── ConsoleKernel.php
    │   └── HttpKernel.php 
    ├── Mails
    │   └── Mailables
    │       ├── Envelope.php
    │       └── Content.php
    ├── Middleware
    │   ├── Authenticate.php
    │   ├── EncryptCookies.php
    │   ├── PreventRequestsDuringMaintenance.php
    │   ├── RedirectIfAuthenticated.php
    │   ├── TrimStrings.php
    │   ├── TrustHosts.php
    │   ├── TrustProxies.php
    │   ├── ValidateSignature.php
    │   └── VerifyCsrfToken.php
    ├── Migrations
    ├── Models
    │   ├── Model.php
    │   ├── UserModel.php
    │   ├── Pivot.php
    │   ├── MorphPivot.php
    │   ├── Builder.php
    │   └── Scope.php
    ├── Notifications
    │   ├── Messages
    │   │   └── MailMessage.php
    │   └── Notification.php
    ├── Policies
    │   └── Policy.php
    ├── Providers
    │   ├── AuthServiceProvider.php
    │   ├── BroadcastServiceProvider.php
    │   ├── EventServiceProvider.php
    │   └── RouteServiceProvider.php
    ├── Requests
    │   ├── Request.php
    │   └── FormRequest.php
    ├── Responses
    │   ├── Response.php
    │   └── RedirectResponse.php
    ├── Resources
    │   ├── JsonResource.php
    │   └── ResourceCollection.php
    ├── Seeders
    ├── Tests
    │   └── TestCase.php
    ├── Traits
    │   └── CreatesApplication.php
    └── Translations

Containers

1. Standard

To create container with necessary files and folders you need to put this command:

php artisan make:container <Name>

Without forced container type will be created standard container structure.

Standard Container's Structure

Container
	├── Actions
	├── Tasks
	├── Models
	├── Loaders
	│   ├── AliasesLoader.php
	│   ├── ProvidersLoader.php
	│   └── MiddlewareLoader.php  
	└── UI
	    ├── WEB
	    │   ├── Routes
	    │   ├── Controllers
	    │   └── Views
	    ├── API
	    │   ├── Routes
	    │   ├── Controllers
	    │   └── Transformers
	    └── CLI
	        ├── Routes
	        └── Commands

2. Default

To create container with default route, controller, view and test file you can via command below:

php artisan make:container <Name> --default

Default Container's Structure

Container
	├── Actions
	├── Tasks
	├── Models
	├── Loaders
	│   ├── AliasesLoader.php
	│   ├── ProvidersLoader.php
	│   └── MiddlewareLoader.php  
	└── UI
	    ├── WEB
	    │   ├── Routes
	    │   │   ├── home.php
	    │   ├── Controllers
	    │   │   ├── HomeController.php 
	    │   ├── Views
	    │   │   ├── home.blade.php
	    │   ├── Tests
	    │   │   ├── Functional
	    │   └── └── └── ExampleTest.php 
	    ├── API
	    │   ├── Routes
	    │   ├── Controllers
	    │   └── Transformers
	    └── CLI
	        ├── Routes
	        └── Commands

3. API

To create container only for API needles you can via command below:

php artisan make:container <Name> --api

API Container's Structure

Container
	├── Actions
	├── Tasks
	├── Models
	├── Loaders
	│   ├── AliasesLoader.php
	│   ├── ProvidersLoader.php
	│   └── MiddlewareLoader.php  
	└── UI
	    └── API
	        ├── Routes
	        ├── Controllers
	        └── Transformers

4. CLI

To create container only for command line interface needles you can via command below:

php artisan make:container <Name> --cli

CLI Container's Structure

Container
	├── Actions
	├── Tasks
	├── Models
	├── Loaders
	│   ├── AliasesLoader.php
	│   ├── ProvidersLoader.php
	│   └── MiddlewareLoader.php  
	└── UI
	    └── CLI
	        ├── Routes
	        └── Commands

5. WEB

To create container only for web needles you can via command below:

php artisan make:container <Name> --web

WEB Container's Structure

Container
	├── Actions
	├── Tasks
	├── Models
	├── Loaders
	│   ├── AliasesLoader.php
	│   ├── ProvidersLoader.php
	│   └── MiddlewareLoader.php  
	└── UI
	    └── WEB
	        ├── Routes
	        ├── Controllers
	        └── Views

6. Full

To create container with full structure you can via command below:

php artisan make:container <Name> --full

Full Container's Structure

Container
	├── Actions
	├── Tasks
	├── Models
	├── Values
	├── Events
	├── Listeners
	├── Policies
	├── Exceptions
	├── Contracts
	├── Traits
	├── Enums
	├── Jobs
	├── Notifications
	├── Providers
	├── Configs
	├── Loaders
	│   ├── AliasesLoader.php
	│   ├── ProvidersLoader.php
	│   └── MiddlewareLoader.php
	├── Mails
	│   └── Templates
	├── Data
	│   ├── Migrations
	│   ├── Seeders
	│   ├── Factories
	│   ├── Criteria
	│   ├── Repositories
	│   ├── Validators
	│   ├── Transporters
	│   └── Rules
	├── Tests
	│   ├── Traits
	│   └── Unit
	└── UI
	    ├── WEB
	    │   ├── Routes
	    │   ├── Controllers
	    │   ├── Requests
	    │   ├── Tests
	    │   │   └── Functional
	    │   └── Views
	    ├── API
	    │   ├── Routes
	    │   ├── Controllers
	    │   ├── Requests
	    │   ├── Tests
	    │   │   └── Functional
	    │   └── Transformers
	    └── CLI
	        ├── Routes
	        ├── Commands
	        └── Tests
	            └── Functional

Laravel console commands

1. Make

This is a list of adapted laravel console commands for the Porto.

Without container name some commands will be created class in the Ship.

Other commands require the container name

make:cast

php artisan make:cast <Name> --container=<Container Name>

make:channel

php artisan make:channel <Name> --container=<Container Name>

make:command

php artisan make:command <Name>
php artisan make:command <Name> --container=<Container Name>

make:component

php artisan make:component <Name> --container=<Container Name>

make:controller

php artisan make:controller <Name> --container=<Container Name>

make:enum

php artisan make:enum <Name> --container=<Container Name>

make:event

php artisan make:event <Name>
php artisan make:event <Name> --container=<Container Name>

make:exception

php artisan make:exception <Name>
php artisan make:exception <Name> --container=<Container Name>

make:factory

php artisan make:factory <Name> --container=<Container Name>

make:job

php artisan make:job <Name>
php artisan make:job <Name> --container=<Container Name>

make:listener

php artisan make:listener <Name> --container=<Container Name>

make:mail

php artisan make:mail <Name>
php artisan make:mail <Name> --container=<Container Name>

make:middleware

php artisan make:middleware <Name>
php artisan make:middleware <Name> --container=<Container Name>

make:model

php artisan make:model <Name> --container=<Container Name>

make:notification

php artisan make:notification <Name>
php artisan make:notification <Name> --container=<Container Name>

make:observer

php artisan make:observer <Name> --container=<Container Name>

make:policy

php artisan make:policy <Name> --container=<Container Name>

make:provider

php artisan make:provider <Name>
php artisan make:provider <Name> --container=<Container Name>

make:request

php artisan make:request <Name> --container=<Container Name> --uiType=api
php artisan make:request <Name> --container=<Container Name> --uiType=web

make:resource

php artisan make:resource <Name> --container=<Container Name>

make:rule

php artisan make:rule <Name> --container=<Container Name>

make:scope

php artisan make:scope <Name> --container=<Container Name>

make:seeder

php artisan make:seeder <Name>
php artisan make:seeder <Name> --container=<Container Name>

make:test

php artisan make:test <Name> --container=<Container Name> --uiType=api
php artisan make:test <Name> --container=<Container Name> --uiType=cli
php artisan make:test <Name> --container=<Container Name> --uiType=web

2. Model

make:show

php artisan make:show --container=<Container Name>

Additional console commands

1. Make

This is a list of console commands for the Porto who does not exists in Laravel.

Without container name some commands will be created class in the Ship.

Other commands require the container name

make:action

php artisan make:action <Name> --container=<Container Name>

make:config

php artisan make:config <Name>
php artisan make:config <Name> --container=<Container Name>

make:contract

php artisan make:contract <Name> --container=<Container Name>

make:helper

php artisan make:helper <Name>

make:repository

php artisan make:repository <Name>

make:task

php artisan make:task <Name> --container=<Container Name>

make:trait

php artisan make:trait <Name> --container=<Container Name>
php artisan make:trait <Name> --container=<Container Name> --test

make:translation

php artisan make:translation <Name> --lang=<lang code>

make:value

php artisan make:value <Name> --container=<Container Name>

License

Released under the MIT License, see LICENSE.

alxdorosenco/porto-for-laravel 适用场景与选型建议

alxdorosenco/porto-for-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.36k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2023 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「template」 「pattern」 「laravel」 「architecture」 「Porto」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 alxdorosenco/porto-for-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alxdorosenco/porto-for-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 alxdorosenco/porto-for-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-01