我正在设置一个新的私有作曲家程序包,其中包含一个名为DatapageSDKProvider的提供程序。
当我将提供程序放在Providers数组中的config / app.php中时: 'Datapage \ DatapageSDK \ Providers \ DatapageSDKProvider' 并尝试输入任何网址,这将引发异常:
找不到“ Datapage \ DatapageSDK \ Providers \ DatapageSDKProvider”
这是我的laravel项目的composer.json:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"repositories": [
{
"type": "package",
"package": {
"name": "ms/datapage-sdk-laravel",
"version": "0.0.3",
"source": {
"url": "url_git",
"type": "git",
"reference": "develop"
},
"options": {
"ssl": {
"verify_peer": "false"
}
}
}
}
],
"require": {
"php": "^7.1.3",
"artesaos/defender": "~0.8.0",
"aws/aws-sdk-php-laravel": "~3.0",
"darkaonline/l5-swagger": "5.7.*",
"doctrine/dbal": "^2.8",
"fideloper/proxy": "^4.0",
"laravel-notification-channels/onesignal": "^1.2",
"laravel/framework": "5.7.*",
"laravel/passport": "^7.0",
"laravel/tinker": "^1.0",
"laravellegends/pt-br-validator": "^5.1",
"league/flysystem-aws-s3-v3": "^1.0",
"league/fractal": "^0.17.0",
"ms/datapage-sdk-laravel": "0.0.*",
"prettus/l5-repository": "2.6.*"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.5",
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.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 --ansi"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
这是我的软件包的composer.json:
{
"name": "datapage/datapage-sdk-laravel",
"description": "Datapage SDK",
"authors": [
{
"name": "Márcio Winicius",
"email": "marciowinicius.mw@gmail.com"
}
],
"autoload": {
"psr-4": {
"Datapage\\DatapageSDK\\": "src/Application"
}
},
"extra": {
"laravel": {
"providers": [
"Datapage\\DatapageSDK\\Providers\\DatapageSDKProvider"
],
"aliases": {
"DatapageSDK": "Datapage\\DatapageSDK\\Facades\\DatapageSDK",
"HttpClient": "Datapage\\DatapageSDK\\Facades\\HttpClient",
"OAuthClient": "Datapage\\DatapageSDK\\Facades\\OAuthClient"
}
}
},
"require": {
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "~5.7"
},
"config": {
"bin-dir": "bin/"
}
}
这是我的提供商所在的包结构:
src \ Application \ Providers
这是我的提供者:
<?php
namespace Datapage\DatapageSDK\Providers;
use Datapage\DatapageSDK\Auth\OAuthClient;
use Datapage\DatapageSDK\DatapageSDKFactory;
use GuzzleHttp\Client;
use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;
class DatapageSDKProvider extends ServiceProvider
{
protected $defer = true;
public function boot()
{
$this->publishes([
__DIR__.'/../../config.php' => config_path('datapage_sdk.php'),
], 'datapage-sdk-config');
}
public function register()
{
$this->app->singleton('DatapageSDK', function() {
return new DatapageSDKFactory();
});
$this->app->singleton('OAuthClient', function() {
return new OAuthClient(new Application());
});
$this->app->singleton('HttpClient', function() {
return new Client([
'headers' => [
'Authorization' => \Datapage\DatapageSDK\Facades\OAuthClient::getToken()
]
]);
});
$this->app->bind(DatapageSDKFactory::class, 'DatapageSDK');
$this->app->bind(OAuthClient::class, 'OAuthClient');
$this->app->bind(Client::class, 'HttpClient');
}
public function provides()
{
return [
DatapageSDKFactory::class, 'DatapageSDK',
OAuthClient::class, 'OAuthClient',
Client::class, 'HttpClient',
];
}
}
编辑: 只是这样更改了我的laravel项目的composer.json:
"repositories": [
{
"type": "vcs",
"url": "http://git2.datapage.com.br/ms/datapage-sdk-laravel.git"
}
],
然后在Require中输入以下内容:
"ms/datapage-sdk-laravel": "dev-develop"
然后进行作曲家更新和作曲家转储自动加载
答案 0 :(得分:0)
您将需要使用require或require-dev来使用它,具体取决于您使用的用途。您可能会将它列为所需的东西,但作曲家不知道从那里安装它。