othercode/laravel-version
Composer 安装命令:
composer require othercode/laravel-version
包简介
A tiny port-adapter version resolver for Laravel apps. Pluggable sources: VERSION file, env var, git tag, or config array.
README 文档
README
A tiny port-adapter version resolver for Laravel apps. Pluggable sources: VERSION file, env var, git tag, or config array.
composer require othercode/laravel-version
- PHP ^8.3
- Laravel ^11.0 || ^12.0
Usage
The package auto-registers its service provider and ships a version() helper. Anywhere in your app:
$version = version(); // SemanticVersion instance (string) $version; // "1.2.3-beta" $version->major; // "1" $version->minor; // "2" $version->patch; // "3" $version->status; // "beta"
Prefer explicit DI? Resolve the manager yourself:
use OtherCode\Laravel\Version\VersionManager; $version = app(VersionManager::class)->version();
Choosing a source
Configure via config/version.php (publish with php artisan vendor:publish --tag=version-config) or env vars:
VERSION_SOURCE=file # file | env | git | config VERSION_FILE_PATH=VERSION # used when VERSION_SOURCE=file VERSION_ENV_KEY=version.value # used when VERSION_SOURCE=env APP_VERSION=v1.2.3-beta # used when VERSION_SOURCE=env VERSION_CONFIG_PREFIX=version # used when VERSION_SOURCE=config
file (default)
Reads a plain-text VERSION file at the app base path. Great for build-time injection:
# build.sh git describe --tags --abbrev=0 > VERSION
env
Reads config('version.value'), typically fed by APP_VERSION. Ideal for platforms like Laravel Cloud where the deploy system injects the release tag as an environment variable. Laravel Cloud does not auto-inject a version — set APP_VERSION per release in the dashboard.
git
Runs git describe --tags --abbrev=0 via Symfony Process. Useful in dev and CI build steps, not in container runtimes: Docker images built from your repo typically do not ship the .git directory, so this adapter will fall back to v0.0.0-dev in production.
config
Reads four keys from a config bag: {prefix}.major, {prefix}.minor, {prefix}.patch, {prefix}.status (prefix defaults to version). Ideal when your app already keeps hardcoded version fragments in config/version.php and you want the file to stay pure data:
// config/version.php (consumer app) return [ 'source' => 'config', 'major' => '1', 'minor' => '2', 'patch' => '3', 'status' => 'beta', ];
Using a custom source
Bind your own adapter anywhere (e.g. in a service provider):
use OtherCode\Laravel\Version\Contracts\VersionSource; use OtherCode\Laravel\Version\SemanticVersion; $this->app->singleton(VersionSource::class, fn () => new class implements VersionSource { public function version(): SemanticVersion { return SemanticVersion::fromString('1.0.0'); } });
Semantic version value object
SemanticVersion is a tiny immutable VO that parses [v]MAJOR[.MINOR[.PATCH]][-STATUS]:
use OtherCode\Laravel\Version\SemanticVersion; SemanticVersion::fromString('v2.5.0-rc1'); SemanticVersion::fromString('2.5'); // pads MINOR/PATCH with "0" SemanticVersion::fromString(''); // throws InvalidArgumentException
The version() helper
The package registers a global version() function guarded by function_exists(). If something in your app already defines version(), ours is silently skipped and you can still use app(VersionManager::class)->version() directly.
License
MIT — see LICENSE.
othercode/laravel-version 适用场景与选型建议
othercode/laravel-version 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 288 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「version」 「semver」 「laravel」 「semantic-version」 「port-adapter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 othercode/laravel-version 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 othercode/laravel-version 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 othercode/laravel-version 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Semantic Versioning Parser and Comparator
Versioning behaviour for eloquent models
Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.
A decent, standards-compliant, Semantic Versioning (SemVer) parser and library
Display a version number
PHP Version Manager for Windows CLI
统计信息
- 总下载量: 288
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 34
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-24