search
HomeBackend DevelopmentPHP TutorialComposer使用内网私有仓库进行包管理

由于长期使用Composer进行包依赖管理,许多公用的类库都会放在GitHub上,在多个项目之间引用依赖,更新版本时,减少了很多成本,但还是存在一些问题:

  • 每次更新,本地需要跑过单元你测试,Commit并Push到Github,等待Composer更新后才生效;
  • 公司级的模块没有办法放在Github上;

官方方案

庆幸的事,Composer 就提供私有仓库的形式:

{ "repositories": [ { "type": "vcs", "url": "http://svn.example.org/projectA/", "trunk-path": "Trunk", "branches-path": "Branches", "tags-path": "Tags" } ]}

具体参考: https://getcomposer.org/doc/05-repositories.md

由于公司内使用的是 Subverison,使用如上方式导入私有仓库,实际上是通过 svn checkout的形式将指定的 tags检出,这时候 vendor目录下将会出现 .svn目录,导致主项目无法提交,甚至在切换 tags时出现无法检出的情况。

在 Composer项目 issue中有许多人反映此问题,解决方案是通过 svn export来代替 svn checkout,需要使用如下插件:

https://github.com/LinearSoft/composer-svn-export

新方案

该插件等于是需要自己搭建一个 packaglist站点,其实仅需要一个 packages.json文件,但是需要有效的 https服务,否则将会出现如下错误:

➜  www.my-project.com composer updateYou are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebugAdded SvnExport repo: NewPackageLoading composer repositories with package information                                                                                                                                               [Composer\Downloader\TransportException]                                                                                                     The "https://packagist.my-project.dev/packages.json" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:    error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed                                                            Failed to enable crypto                                                                                                                      failed to open stream: operation failed         

如果没有这样的 https服务,可以选择在 gist上建一个 packages.json文件来达到效果:

{ "packages": { "tc/analyse": { "0.9.2": { "name": "tc/analyse", "version": "0.9.2", "source": { "type": "svn", "url": "https://svn.tc.dev/library/analyse", "reference": "/tags/0.9.2" } }, "0.9.3": { "name": "tc/analyse", "version": "0.9.3", "source": { "type": "svn", "url": "https://svn.tc.dev/library/analyse", "reference": "/tags/0.9.3" } }, "dev-master": { "name": "tc/analyse", "version": "dev-master", "source": { "type": "svn", "url": "https://svn.tc.dev/library/analyse", "reference": "/trunk" } } } }}

主项目中 composer.json填充上该 Gist地址

{ "require" : { "php" : ">=5.4.0", "tc/analyse" : "0.9.3", "linearsoft/composer-svn-export" : "^0.1.2" }, "extra" : { "svn-export-repositories" : [ { "name" : "TC", "type" : "composer", "url" : "https://gist.githubusercontent.com/lancerhe/379eeee89fd0db8c0c4ca19c6bddas2f/raw/915a720635949c9d4013746845b952f88af358db" } ] }, "minimum-stability" : "stable"}

运行 composer update

➜  www.my-project.com composer updateYou are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebugAdded SvnExport repo: TCLoading composer repositories with package informationUpdating dependencies (including require-dev)  - Updating tapcash/analyse (0.9.2 => 0.9.3)    Exporting /tags/0.9.3Writing lock fileGenerating autoload files

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

HTTP Method Verification in LaravelHTTP Method Verification in LaravelMar 05, 2025 pm 04:14 PM

Laravel simplifies HTTP verb handling in incoming requests, streamlining diverse operation management within your applications. The method() and isMethod() methods efficiently identify and validate request types. This feature is crucial for building

Discover File Downloads in Laravel with Storage::downloadDiscover File Downloads in Laravel with Storage::downloadMar 06, 2025 am 02:22 AM

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),