简体   繁体   English

自动加载文件夹而不更改composer.json文件-Laravel 5.4

[英]Autoload folder without changing composer.json file - Laravel 5.4

I've created a package that creates a folder in the root of the project. 我创建了一个包,该包在项目的根目录下创建了一个文件夹。 Creating it in the app folder is for me not clean enough. 对我来说,在app文件夹中创建它还不够干净。 Cause I don't want it to look like it's merged with the laravel framework. 因为我不希望它看起来像与laravel框架合并。 This package is for our company and will be used a lot. 该软件包适用于我们公司,将被大量使用。

So instead of changing the composer.json file everytime to add the folder to the autoloader I'm trying to just autoload it from the package. 因此,与其每次都更改composer.json文件以将该文件夹添加到自动加载器中,我不打算从包中自动加载它。

Is something like that possible and how? 这样有可能吗?

Are you saying that you do not want to add it in your composer.json file here? 你是说你希望将其添加到您的composer.json这里的文件?

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/",
        "Company\\": "company/"
    }
},

That is what I would do. 那就是我会做的。


What if you just use the folder structure as the autoloader namespace? 如果仅将文件夹结构用作自动加载器名称空间该怎么办? That should work. 那应该工作。 For example: 例如:

<?php

use Company\Foo;

new Bar();

Where you would have a folder called company/Foo with all the classes inside declaring their namespace like so: 在其中有一个名为company/Foo的文件夹中,其中所有类都在声明其名称空间,如下所示:

<?php

namespace Company\Foo;

class Bar {
    //
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM