定制 lifespikes/laravel-bare 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

lifespikes/laravel-bare

Composer 安装命令:

composer require lifespikes/laravel-bare

包简介

README 文档

README

Component of lifespikes/lifespikes

A very minimalist and customizable Laravel installation. Ideal for customizing Laravel path resolutions and discovering service providers when working with a monorepo using symplify/monorepo-builder

Installation

Setting up Bare is a bit different from a regular Laravel installation:

  • No boilerplate/skeleton code
  • Purely service-provider driven
  • Bootstrap and other startup code is not included

You'll need to start by of course, installing the module:

composer require @lifespikes/laravel-bare

Then, your entrypoint needs to be set up. You will need to create an entrypoint for artisan and another one for your web app if applicable:

#!/usr/bin/env php
<?php

/*
 * This takes care of bootstrapping the application
 * and its paths. While it might look different, it's still
 * the same as a regular Laravel installation in terms
 * of behavior. Laravel Bare just implements Laravel
 * original scaffold differently, but the framework itself
 * is kept untouched.
 */
 
use function LifeSpikes\LaravelBare\Bootstrap\bare;

/* Define before any operations take place, for accuracy */
define('LARAVEL_START', microtime(true));

/* Composer autoloader */
require __DIR__ . '/vendor/autoload.php';

/* Specify the root dir and bootstrap */
bare(__DIR__)->artisan();

Setting up your web entrypoint is essentially the same:

<?php

/* Assuming we're in public/index.php */

use function LifeSpikes\LaravelBare\Bootstrap\bare;

define('LARAVEL_START', microtime(true));
require __DIR__.'/../vendor/autoload.php';

/* Go up a level since this is usually in a subdirectory */
bare(__DIR__ . '/../')->web();

Usage

There's no special configuration or usage for Bare besides its path configuration and monorepo-builder support.

Customizing Directories

The bare() bootstrap helper takes a base path as its first argument. However, you can also pass an array of paths that Laravel will use as values when trying to resolve against path instances like resource_path, database_path, etc.

bare([
    'base' => __DIR__, /* Root Dir */
    
    /* Everything else solves relative to base */
    'public' => 'static',
    'cache'  => 'storage/cache',
    ...
])->web();

Defaults can be found in the config/paths.php file.

Local Package Discovery

If you have built Laravel packages in the past, you're probably familiar with the {"extra": {"laravel": {...}}} section of your composer.json file.

However, using this section in your standard, root-level composer.json file will have no effect, since Laravel reads off your vendor/composer/installed.json manifest when performing package discovery.

Bare adds a bit of logic during registration to allow local packages like these to be discovered without having to manually register them against the container instance.

This is especially helpful when building monorepo where you may have multiple Laravel packages you wish to isolate.

Read more about package discovery.

Building Apps on Bare

Bare is meant to be used as a base for building package-driven SOLID codebases. This means you'll have to write your own service providers and bootstrap code as explained earlier. Primarily, for example, we use bare as a simple way for us to write modularized, independent packages that make up a large app. The Laravel documentation is a great place to start:

https://laravel.com/docs/9.x/packages

FAQ

Where is the [X] directory?

Bare allows you to use Laravel as a library. It contains all the default configurations found in the laravel/laravel scaffold, but removes all dependencies in the App\ namespace.

You'll need to use service providers to manually bind config, events, listeners, etc. to your module.

If you're wondering why we did this, read the section below.

Why go Bare?

When people think about Laravel, they usually think of two things:

  • A web framework
  • The laravel/laravel repository

Most people are unaware that these terms are exclusive of each other. The components that make up the framework are actually contained in the laravel/framework repository.

Libraries have historically been published by the maintainer, and then implemented by the developer. Maintainer code is not present in the app's codebase. This pattern is often seen in low-level languages like C, C++, ASM, etc. (OpenSSL, SDL, Vulkan, OpenGL, are good examples)

This project is intended for developers with an architectural background looking to harness the power of Laravel, while maintaining the freedom to implement their own structures and patterns.

lifespikes/laravel-bare 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 25.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 10
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2022-08-04