Laravel 개발 패키지에서 도우미 메서드 구성을 사용하는 경우 Vendor:publish를 실행할 때 오류가 보고됩니다.
Dec 01, 2016 am 12:56 AM
공급자를 사용하여 서비스를 등록하는 패키지를 직접 개발했지만 구성을 가져오는 데 config() 메서드가 사용되었습니다. 문제는 구성 파일이 아직 게시되지 않았다는 것입니다. 내 생각이 틀렸다고 생각합니다.
코드는 다음과 같습니다.
<code>class SuperViewConfigProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // Publish the config file to $this->publishes([ __DIR__.'/../../config/config.php' => config_path('superview.php'), ]); } }</code>
<code>class SuperViewModelProvider extends ServiceProvider { /** * Indicates if loading of the provider is deferred. * * @var bool */ protected $defer = true; /** * Register any application services. * * @return void */ public function register() { // Get config, then bind automaticly $models = array_keys(config('superview.models')); foreach ($models as $model) { $this->app->singleton(config('superview.model_prefix') . $model, function($app) use ($models, $model) { return new $models[$model]; }); } } /** * Get the services provided by the provider. * * @return array */ public function provides() { return array_map(function($value) { return config('superview.model_prefix') . $value; }, array_keys(config('superview.models'))); } }</code>
그런 다음 다음을 실행합니다: php artisan Vendor:publish --provider="SuperViewProvidersSuperViewConfigProvider"
구성 콘텐츠가 존재하지 않는다는 오류가 보고됩니다.
답글 내용:
공급자를 사용하여 서비스를 등록하는 패키지를 직접 개발했지만 구성을 가져오는 데 config() 메서드가 사용되었습니다. 문제는 구성 파일이 아직 게시되지 않았다는 것입니다. 내 생각이 틀렸다고 생각합니다.
코드는 다음과 같습니다.
<code>class SuperViewConfigProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // Publish the config file to $this->publishes([ __DIR__.'/../../config/config.php' => config_path('superview.php'), ]); } }</code>
<code>class SuperViewModelProvider extends ServiceProvider { /** * Indicates if loading of the provider is deferred. * * @var bool */ protected $defer = true; /** * Register any application services. * * @return void */ public function register() { // Get config, then bind automaticly $models = array_keys(config('superview.models')); foreach ($models as $model) { $this->app->singleton(config('superview.model_prefix') . $model, function($app) use ($models, $model) { return new $models[$model]; }); } } /** * Get the services provided by the provider. * * @return array */ public function provides() { return array_map(function($value) { return config('superview.model_prefix') . $value; }, array_keys(config('superview.models'))); } }</code>
그런 다음 다음을 실행합니다: php artisan Vendor:publish --provider="SuperViewProvidersSuperViewConfigProvider"
구성 콘텐츠가 존재하지 않는다는 오류가 보고됩니다.
공급자의 register
메소드에서 mergeConfigFrom
을 먼저 호출합니다.
$this->mergeConfigFrom(__DIR__.'/../../config/config.php', 'superview');
패키지의 구성 파일을 기본으로 사용한 다음 사용자 앱 디렉터리의 구성을 병합하고 마지막으로 슈퍼뷰의 구성을 가져와 현재 구성 저장소에 설정한다는 의미입니다.
ServiceProvider
라고 써도 되지만, 이 파일이 있는지 확인해보시면 어떨까요?
<code>__DIR__.'/../../config/config.php</code>
config가 출시되기 전에 여기서 config를 사용할 수 있는지 잘 모르겠습니다
<code>public function provides() { return array_map(function($value) { return config('superview.model_prefix') . $value; }, array_keys(config('superview.models'))); }</code>

인기 기사

인기 기사

뜨거운 기사 태그

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Ubuntu 및 Debian용 PHP 8.4 설치 및 업그레이드 가이드

PHP 개발을 위해 Visual Studio Code(VS Code)를 설정하는 방법
