在作曲家自动加载器中找不到类



我的composer.json里有这个

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "alchemy/zippy": "^0.4.8",
        "barryvdh/laravel-debugbar": "^3.1",
        "fideloper/proxy": "~3.3",
        "graham-campbell/exceptions": "^10.0",
        "intervention/image": "^2.4",
        "intervention/imagecache": "^2.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "laravelcollective/html": "^5.5",
        "symfony/dom-crawler": "^3.3"
    },
    "files": [
        "vendor/redbutton/text-image-alpha/vendor/autoload.php"
    ],
    "require-dev": {
        "filp/whoops": "^2.1",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~6.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r "file_exists('.env') || copy('.env.example', '.env');""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

我的软件包的 php 文件在 laravel 安装中: /vendor/redbutton/text-image-alpha/src/

当我尝试调用文件时,我收到以下消息:

Class 'Class 'RedButtonTextImageAlphaTextImageAlpha' not found' not found

我用它来尝试调用类:

$image     = new RedButtonTextImageAlphaTextImageAlpha( 'some string' );

/vendor/redbutton/text-image-alpha/src/TextImageAlpha.php中的文件如下所示:

<?php
namespace RedButtonTextImageAlpha;
use RedButtonTextImageAlphaExceptions;
use RedButtonToolsObjects;

/**
 * TextImageAlpha class convert a text to image.
 *
 * @author Tomas Rathouz <trathouz at gmail.com>
 */
class TextImageAlpha
{
   // lots of code
}

这是我的第一个作曲家包,我真的不知道这里出了什么问题。有人可以向我解释我做错了什么吗?

好消息。我已经在Bitbucket上查看了您的软件包,并且您正在composer.json中这样做:


composer.json中删除不必要的代码

我注意到在粘贴composer.json中手动添加了一些供应商文件

"files": [
    "vendor/redbutton/text-image-alpha/vendor/autoload.php"
],

嵌套在/vendor中的/vendor没有意义,因为它可能会重复自动加载并破坏它。

此外,我在require部分中看不到redbutton/text-image-alpha,它应该在哪里。


如何以正确的方式添加包?

要安装软件包,只需调用作曲家

composer require redbutton/text-image-alpha

仅此而已。

它应该出现在composer.json require部分中。作曲家将通过composer.json的规则自动加载它 - 这里。


测试

我尝试了以下代码,并且正确找到了类:

<?php 
require __DIR__ . '/vendor/autoload.php';
$image = new RedButtonTextImageAlphaTextImageAlpha('some string');
var_dump($image);

composer.json

{
    "require": {
        "redbutton/text-image-alpha": "^1.0"
    }
}

相关内容

  • 没有找到相关文章

最新更新