该包已被放弃且不再维护。没有建议的替代包。

轻松自定义您的Laravel路径。

v1.0 2015-12-23 20:35 UTC

This package is auto-updated.

Last update: 2020-04-06 18:25:55 UTC


README

Caffeinated Path

Laravel 5.2 Source License

注意:这最初是Caffeinated/Path包的一部分。我已经将其提取出来成为一个独立的包。

Caffeinated Path允许您轻松自定义Laravel 5应用的默认结构。这意味着您可以将默认的Laravel框架结构

laravel5/
|-- app/
|-- bootstrap/
|-- config/
|-- database/
|-- public/
|-- resources/
|-- storage/
|-- tests/

配置为类似

laravel5/
|-- app/
|-- bootstrap/
|-- system/
	|-- config/
	|-- database/
	|-- resources/
	|-- storage/
	|-- tests/

该包遵循FIG标准PSR-1、PSR-2和PSR-4,以确保共享PHP代码之间的高互操作性。

快速安装

通过Composer安装此包。

composer require caffeinated/path=~1.0

此操作完成后,只需将服务提供者类添加到项目的config/app.php文件中

服务提供者

Caffeinated\Path\PathServiceProvider::class,

实例化Caffeinated Path应用

首先,您需要在bootstrap/app.php文件中将Laravel的Illuminate Foundation Application替换为Caffeinated Path Application实例。只需按照如下方式替换即可

$app = new Caffeinated\Path\Application(
	realpath(__DIR__.'/../')
);

Caffeinated Path Application扩展了Illuminate Foundation Application,并添加了通过提供的path配置文件自定义目录的能力。

现在您可以按需配置任何基本路径!但请注意,某些路径的设置可能比其他路径需要更多的工作

继续阅读以了解如何配置这些路径,或使用上面的链接直接跳转到任何部分。

设置自定义配置路径

如果您想移动您的config目录,在创建新的Caffeinated Path Application实例时,将路径作为第二个参数提供

$app = new Caffeinated\Path\Application(
	realpath(__DIR__.'/../'),
	realpath(__DIR__.'/../system/config/')   // Your custom config path
);

更改引导路径

Caffeinated Path不提供更改您的bootstrap目录路径的方法,因为您需要在以下三个文件中进行简单的编辑(别担心,并不复杂)

  • public/index.php
  • bootstrap/app.php
  • bootstrap/autoload.php

步骤1:更新public/index.php

首先,您需要更改public/index.php文件中的以下两个require路径

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/

require __DIR__.'/../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

步骤2:更新bootstrap/app.php

其次,打开您的bootstrap/app.php文件并更新相关路径到应用的基础目录

$app = new Caffeinated\Path\Application(
	realpath(__DIR__.'/../')                   // Update this path
);

步骤3:更新bootstrap/autoload.php

最后,打开您的 bootstrap/autoload.php 文件,并更新 Composer 自动加载编译后的类 路径

/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Include The Compiled Class File
|--------------------------------------------------------------------------
|
| To dramatically increase your application's performance, you may use a
| compiled class file which contains all of the classes commonly used
| by a request. The Artisan "optimize" is used to create this file.
|
*/

$compiledPath = __DIR__.'/../storage/framework/compiled.php';

这就完成了!只需启动您的应用程序进行验证即可。