adachsoft/git-platform
Composer 安装命令:
composer require adachsoft/git-platform
包简介
Thin, test-friendly Git hosting abstraction for PHP with GitLab repository management.
README 文档
README
adachsoft/git-platform is a small PHP library that provides a thin, test-friendly abstraction over Git hosting
providers.
The first implementation in this repository targets GitLab (REST API v4) and focuses on repository management and offset-based pagination for listing repositories.
The only layer you need to use as a consumer is the PublicApi layer, in particular
AdachSoft\GitPlatform\PublicApi\GitRepository\GitRepositoryFacadeInterface and
AdachSoft\GitPlatform\PublicApi\GitRepository\Builder\GitRepositoryFacadeBuilder.
This package is intended to be used as a library in other applications (not as a standalone service).
Requirements
- PHP ^8.1
ext-json- A PSR-18 HTTP client implementation
- PSR-17 request & stream factories
This library is tested with:
guzzlehttp/guzzleas PSR-18 clientguzzlehttp/psr7as PSR-7 implementation and factories
Installation
Install the library via Composer:
composer require adachsoft/git-platform
The package itself only requires PSR interfaces:
psr/http-clientpsr/http-factory
In a typical setup you will also install a concrete implementation, e.g.:
composer require guzzlehttp/guzzle
composer require guzzlehttp/psr7
If you already have a PSR-18 client and PSR-17 factories in your project, you can reuse them – the library will use them under the hood when you build the facade.
Quick Start (GitLab)
The recommended entry point is the GitRepositoryFacadeBuilder, which creates a ready-to-use
GitRepositoryFacadeInterface instance for GitLab.
<?php
use AdachSoft\GitPlatform\Infrastructure\GitLab\GitLabConfigDto;
use AdachSoft\GitPlatform\PublicApi\GitRepository\Builder\GitRepositoryFacadeBuilder;
use AdachSoft\GitPlatform\PublicApi\GitRepository\GitRepositoryFacadeInterface;
$baseUrl = 'https://gitlab.com';
$accessToken = 'your-gitlab-personal-access-token';
$gitLabConfig = new GitLabConfigDto($baseUrl, $accessToken);
$builder = new GitRepositoryFacadeBuilder();
/** @var GitRepositoryFacadeInterface $gitRepositoryFacade */
$gitRepositoryFacade = $builder->build($gitLabConfig);
From now on you only interact with the GitRepositoryFacadeInterface and PublicApi DTOs.
Listing Repositories (Pagination)
The GitRepositoryFacade::listRepositories() method exposes offset-based pagination on top of GitLab projects API.
Default pagination
Calling listRepositories() without arguments uses the default pagination:
page = 1perPage = 20
use AdachSoft\GitPlatform\PublicApi\GitRepository\Dto\ListRepositoriesQueryDto;
use AdachSoft\GitPlatform\PublicApi\GitRepository\GitRepositoryFacadeInterface;
use AdachSoft\GitPlatform\PublicApi\GitRepository\Dto\PaginatedRepositoryCollectionDto;
use AdachSoft\GitPlatform\PublicApi\GitRepository\Collection\RepositoryCollection;
use AdachSoft\GitPlatform\PublicApi\GitRepository\Dto\RepositoryDto;
/** @var GitRepositoryFacadeInterface $gitRepositoryFacade */
$paginated = $gitRepositoryFacade->listRepositories();
// $paginated is an instance of PaginatedRepositoryCollectionDto
$items = $paginated->items; // RepositoryCollection
foreach ($items as $repository) {
/** @var RepositoryDto $repository */
echo $repository->id . ' ' . $repository->fullName . PHP_EOL;
}
// Pagination metadata
$page = $paginated->page; // int
$perPage = $paginated->perPage; // int
$totalItems = $paginated->totalItems; // ?int (may be null when GitLab does not return it)
$totalPages = $paginated->totalPages; // ?int
Custom pagination
To request a specific page and page size, construct ListRepositoriesQueryDto and pass it to listRepositories():
use AdachSoft\GitPlatform\PublicApi\GitRepository\Dto\ListRepositoriesQueryDto;
use AdachSoft\GitPlatform\PublicApi\GitRepository\GitRepositoryFacadeInterface;
/** @var GitRepositoryFacadeInterface $gitRepositoryFacade */
$query = new ListRepositoriesQueryDto(page: 2, perPage: 50);
$paginated = $gitRepositoryFacade->listRepositories($query);
// You can now assert or use pagination metadata
assert($paginated->page === 2);
assert($paginated->perPage === 50);
Creating a Repository
Use CreateRepositoryDto to create a new repository:
use AdachSoft\GitPlatform\PublicApi\GitRepository\Dto\CreateRepositoryDto;
use AdachSoft\GitPlatform\PublicApi\GitRepository\GitRepositoryFacadeInterface;
use AdachSoft\GitPlatform\PublicApi\GitRepository\Dto\RepositoryDto;
/** @var GitRepositoryFacadeInterface $gitRepositoryFacade */
$dto = new CreateRepositoryDto(
name: 'my-new-repository',
description: 'Example project managed via git-platform',
private: null, // optional, let GitLab defaults decide
visibility: 'private', // or 'public', 'internal' depending on your GitLab setup
);
/** @var RepositoryDto $repository */
$repository = $gitRepositoryFacade->createRepository($dto);
echo $repository->id; // string
echo $repository->fullName; // string
Updating a Repository
Use UpdateRepositoryDto to update an existing repository. You only need to provide the fields you want to change:
use AdachSoft\GitPlatform\PublicApi\GitRepository\GitRepositoryFacadeInterface;
use AdachSoft\GitPlatform\PublicApi\GitRepository\Dto\RepositoryDto;
use AdachSoft\GitPlatform\PublicApi\GitRepository\Dto\UpdateRepositoryDto;
/** @var GitRepositoryFacadeInterface $gitRepositoryFacade */
$dto = new UpdateRepositoryDto(
repositoryId: '123456',
name: 'renamed-repository',
description: 'Updated description',
private: null, // keep previous value
visibility: 'private', // change visibility
hasIssues: true,
hasWiki: false,
);
/** @var RepositoryDto $repository */
$repository = $gitRepositoryFacade->updateRepository($dto);
echo $repository->name; // "renamed-repository"
Getting a Single Repository
use AdachSoft\GitPlatform\PublicApi\GitRepository\GitRepositoryFacadeInterface;
use AdachSoft\GitPlatform\PublicApi\GitRepository\Dto\RepositoryDto;
/** @var GitRepositoryFacadeInterface $gitRepositoryFacade */
$repositoryId = '123456';
/** @var RepositoryDto $repository */
$repository = $gitRepositoryFacade->getRepository($repositoryId);
echo $repository->fullName;
Deleting a Repository
use AdachSoft\GitPlatform\PublicApi\GitRepository\GitRepositoryFacadeInterface;
/** @var GitRepositoryFacadeInterface $gitRepositoryFacade */
$repositoryId = '123456';
$gitRepositoryFacade->deleteRepository($repositoryId);
Versioning
This library follows semantic versioning (SemVer).
- Current stable version:
0.1.0(initial release) - See
CHANGELOG.mdfor a human-readable list of changes between versions.
Error Handling
The facade methods may throw domain-specific exceptions when underlying operations fail, for example when:
- the repository cannot be found,
- there is a connection problem with the GitLab API,
- the GitLab API returns an unexpected response.
Make sure to wrap calls in your own error handling or translate these exceptions to your application-level errors.
License
This library is released under the MIT License.
adachsoft/git-platform 适用场景与选型建议
adachsoft/git-platform 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「git」 「repository」 「repositories」 「gitlab」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adachsoft/git-platform 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adachsoft/git-platform 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adachsoft/git-platform 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easily manage git hooks in your composer config
MediaWiki extension that allows embedding external content, specified by URL, into your wiki pages
Nagios plugin to verify a git repository.
A PSR-7 compatible library for making CRUD API endpoints
GitHub Webhook Listener with plugin-based API for creating your own triggerered actions
This project will create a WordPress base installation using wp-cli/wp-cli package and using vlucas/phpdotenv package to expose configuration values in PHP $_ENV super global.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 39
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-21