作曲家,Laravel和本地软件包 [英] Composer, Laravel and local packages

查看:146
本文介绍了作曲家,Laravel和本地软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我有一个不是存储库的软件包,我正在尝试使其与Laravel和作曲家一起使用.它仍然位于供应商文件夹下,唯一的问题是,如果我简单地设置:

My issue is I have a package which isn't a repository and I am trying to get it to play nice with Laravel and composer. It is still located under the vendor folder, the only issue is that if I simply set:

"psr-0": {
        "Test\\Test": "vendor/test/test/src/"
    }

这将加载服务提供商,但所有控制器等均不会自动加载.用没有自己的存储库的幼虫实现软件包的正确方法是什么?还是这与软件包的性质背道而驰,而应该简单地在应用程序控制器下进行构造.

This will load the service provider but none of the controllers etc will autoload. What is the correct way to implement a package with larval that does not have it's own repository. Or does this go against the nature of packages and this should simply be structured under the applications controllers.

该软件包是由我使用Workbench创建的,但是我发现我并不需要它作为单独的存储库,但是将其保留为软件包仍然会很好.因此,其结构与常规软件包完全相同:

The package was created by me using workbench but I found i did not really need this as a separate repository but it would still be good to keep it as a package. Therefore the structure is exactly the same as a regular package:

vendor
    testvendor
        testpackage
            public
            src
            tests
            .gitignore
            composer.json
            phpunit.xml

更新:

作为我目前正在使用的解决方案:

As a solution for the time being I am using:

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",
        "vendor/package"
    ]
},

作为类映射中的条目.展望未来,我可能会将其重构到app文件夹或为此程序包创建一个存储库.

As an entry in the class map. Looking forward I will probably refactor this into the app folder or create a repository for this package.

推荐答案

如果您将某些类称为包",则不应将这些文件添加到供应商文件夹中.该文件夹由作曲家管理,您随时可以松开它.在您的应用程序中创建一个子文件夹,并将这些文件放在此处.

If you have some classes that you're calling "package", you're not supposed to add those files to your vendor folder. This folder is managed by composer and at any time you might loose it. Create a subfolder in your application and put those files there.

您必须确保PSR-0自动加载对文件夹结构中的每个文件都适用.因此,如果您的根目录为vendor/test/test/src/并且名称空间为

You have to be sure your PSR-0 autoloading will work for every single file in your folder structure. So, if your root is vendor/test/test/src/ and your namespace is

Test\\Test

您的所有文件都必须位于

All your files must be in

vendor/test/test/src/Test/Test/ClassFileName.php

PSR-4更易于处理和理解,

PSR-4 is easier to deal and understand, this

"psr-4": {
    "Test\\Test\\": "vendor/test/test/src/"
}

意味着您的文件必须像这样:

Means that your files would have to be like:

vendor/test/test/src/ClassFileName.php

仔细检查您的名称空间.将名称空间与PSR-0一起使用时很容易出错,并且请记住

Doublecheck your namespaces. It's easy to make mistakes when using namespaces with PSR-0 and remember that

composer dump-autoload

每次更改composer.json中的内容或创建新文件时都必须运行.如果是简单的类自动加载,则每次创建文件时,如果是PSR-X自动加载,则每次创建或更新composer.json文件中的名称空间时.

Must be ran every time you change things in composer.json or create new files. If it's a simple class autoloading, every time you create a file, if it's a PSR-X autoloading, everytime you create or update a namespace in your composer.json file.

如果您真正拥有的是一个软件包,则应使用Composer:当您将软件包结构化为composer软件包时(以Laravel的composer.json为例),将其添加到应用程序中的正确方法(如果不是) Packagist中的列表是通过repositories.

If what you have is is really a package you should use Composer: when your package is structured as a composer package (check Laravel's composer.json as an example), the correct way of adding it to your application, if it's not list in Packagist, is via repositories.

您可以在公共VCS存储库中拥有(非包装商)软件包:

You can have (non-packagist) packages in a public VCS repository:

{
    "require": {
        "monolog/monolog": "dev-bugfix"
    },

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/igorw/monolog"
        }
    ]
}

您可以在受密码保护的VCS存储库(git,bitbucket ...)中拥有(非包装师)软件包:

You can have (non-packagist) packages in a protected by password VCS repository (git, bitbucket...):

{
    "require": {
        "vendor/my-private-repo": "dev-master"
    },
    "repositories": [
        {
            "type": "vcs",
            "url":  "git@bitbucket.org:vendor/my-private-repo.git"
        }
    ]
}

您可以将软件包压缩到硬盘中,并通过artifact存储库类型加载它们:

You can have your packages zipped in your hard drive and load them via the artifact repository type:

"repositories": [
    {
        "type": "artifact",
        "url": "path/to/directory/with/zips/"
    }
],

这篇关于作曲家,Laravel和本地软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆