问题描述
我想在我的 Laravel 5 项目中编辑从 composer 提取的包,但是我相信如果我运行 composer update
并且该包的新版本已经发布,我将失去所有我的变化.我应该如何去编辑包?有没有办法将包从供应商目录中复制出来,以便我可以在项目的其他地方使用它?
I want to edit a package I pulled from composer in my Laravel 5 project, however i believe that if I ran composer update
and a new version of this package has been released, I will lose all of my changes. How should I go about editing the package? Is there a way to copy package out of the vendor directory so I can use it somewhere else in my project?
推荐答案
编辑 composer 包实际上是不安全的,因为你指出的原因.
It actually isn't safe to edit composer packages, for the very reason you point out.
我所做的是扩展我想要/需要更改的类.
What I do is extends the classes that I want/need to change.
我在这里使用 Filesystem 类完成了它.它不能确保它不会中断,但它可以让您在不覆盖更改的情况下进行更新.
I have done it here with the Filesystem class. It doesn't ensure that it won't break, but it does let you update without overwriting your changes.
config/app.php
<?php
return [
'providers' => [
// 'IlluminateFilesystemFilesystemServiceProvider',
'MyAppFilesystemFilesystemServiceProvider',
],
'aliases' => [
...
],
];
MyAppFilesystemFilesystemServiceProvider.php
<?php namespace MyAppFilesystem;
use Config;
use Storage;
use LeagueFlysystemFilesystem;
use DropboxClient as DropboxClient;
use LeagueFlysystemDropboxDropboxAdapter;
use IlluminateFilesystemFilesystemManager as LaravelFilesystemManager;
class FilesystemManager extends LaravelFilesystemManager{
public function createDropboxDriver(array $config)
{
$client = new DropboxClient($config['token'], $config['app']);
return $this->adapt(
new Filesystem(new DropboxAdapter($client))
);
}
}
这篇关于在 Laravel & 中安全地编辑第三方作曲家(供应商)包防止在发布新版本的软件包时丢失自定义更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!