承接 mortexa/laravel-arkitect 相关项目开发

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

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

mortexa/laravel-arkitect

Composer 安装命令:

composer require mortexa/laravel-arkitect

包简介

Test and enforce architectural rules in your Laravel applications

README 文档

README

art/laravel-arkitect.png

Laravel Arkitect

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Laravel Arkitect lets you test and enforce your architectural rules in your Laravel applications, and it's a PHPArkitect wrapper for Laravel. This package helps you to keep your app's architecture clean and consistent.

├─ storage
├─ tests
│   ├─ Architecture ✅
│   ├─ Browser
│   ├─ Feature
│   └─ Unit
└─ vendor

Installation

You can install the package via Composer:

composer require mortexa/laravel-arkitect --dev

Usage

First, you should create your architectural rules by running the following Artisan command:

php artisan make:arkitect ControllersNaming

By running the command, the ControllersNaming.php file will be created in your application's tests/Architecture directory like this:

<?php

namespace Tests\Architecture;

use Arkitect\Rules\DSL\ArchRule;
use Mortexa\LaravelArkitect\Contracts\RuleContract;
use Mortexa\LaravelArkitect\Rules\BaseRule;

class ControllersNaming extends BaseRule implements RuleContract
{
    /**
     * Define your architectural rule
     *
     * @link https://github.com/phparkitect/arkitect
     *
     * @return \Arkitect\Rules\DSL\ArchRule
     */
    public static function rule(): ArchRule
    {
        // TODO: Implement rule() method.
    }

    /**
     * Define the path related to your rule
     *
     * @example app/Http/Controllers
     *
     * @return string
     */
    public static function path(): string
    {
        // TODO: Implement path() method.
    }
}

Then, you must implement rule() and path() methods based on the following example.

And finally, you can run your tests by the following command:

php artisan test:arkitect

Done!

If you want to stop checking command immediately after first violation, you can use --stop-on-failure option.

For all available rules, please take a look at the PHPArkitect repository: https://github.com/phparkitect/arkitect

Default rules

Some opinionated rules are provided by the package and apply by default. These rules are about Laravel user-land structure. You are free to customize or ignore them entirely by publishing config file.

Example

<?php

namespace Tests\Architecture;

use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\DSL\ArchRule;
use Arkitect\Rules\Rule;
use Mortexa\LaravelArkitect\Contracts\RuleContract;
use Mortexa\LaravelArkitect\Rules\BaseRule;

class ControllersNaming extends BaseRule implements RuleContract
{
    public static function rule(): ArchRule
    {
        return Rule::allClasses()
            ->that(new ResideInOneOfTheseNamespaces('App\Http\Controllers'))
            ->should(new HaveNameMatching('*Controller'))
            ->because('It\'s a Laravel naming convention');
    }

    public static function path(): string
    {
        return 'app/Http/Controllers';
    }
}

Configuration

If you want to customize the default rules provided by the package, You can publish the Laravel Arkitect configuration file using the following Artisan command:

php artisan vendor:publish --provider="Mortexa\LaravelArkitect\ArkitectServiceProvider" --tag="config"

The arkitect configuration file will be placed in your application's config directory.

// config/arkitect.php

<?php

use ...

return [
    'rules' => [
        'naming' => [
            ControllersNaming::class,
            ExceptionsNaming::class,
            NotificationsNaming::class,
            ObserversNaming::class,
            ProvidersNaming::class,
            RequestsNaming::class,
            ResourcesNaming::class,
            ChannelsNaming::class,
            SeedersNaming::class,
            PoliciesNaming::class,
            FactoriesNaming::class,
            ScopesNaming::class,
            BuildersNaming::class,
            ContractsNaming::class,
            RepositoriesNaming::class,
            MailsNaming::class,
        ],
        'extending' => [
            ControllersExtending::class,
            CommandsExtending::class,
            ExceptionsExtending::class,
            RequestsExtending::class,
            ResourcesExtending::class,
            ResourceCollectionsExtending::class,
            ModelsExtending::class,
            NotificationsExtending::class,
            ProvidersExtending::class,
            ViewsExtending::class,
            FactoriesExtending::class,
            SeedersExtending::class,
            MailsExtending::class,
        ],
        'implementing' => [
            RulesImplementing::class,
            CastsImplementing::class,
            ScopesImplementing::class,
            JobsImplementing::class,
        ],
    ],
    'ignored_namespaces' => [],
];

Ignore namespaces

If you want to ignore any namespaces from being under architectural test, you should add the related path to ignored_namespaces key in configuration file.

Contributing

Thank you for considering contributing! If you find an issue, or have a better way to do something, feel free to open an issue, or a PR.

Licence

This repository is open-sourced software licensed under the MIT license.

mortexa/laravel-arkitect 适用场景与选型建议

mortexa/laravel-arkitect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 461.51k 次下载、GitHub Stars 达 119, 最近一次更新时间为 2022 年 08 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 461.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 119
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 119
  • Watchers: 4
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-05