Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Package Versions Laravel Package

ocramius/package-versions

Fast, zero‑I/O access to Composer dependency versions at runtime. Reads version data compiled from composer.lock during install/update, so calls are cheap. Use PackageVersions\Versions::getVersion('vendor/package') to embed or log exact versions.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package with composer require ocramius/package-versions. After installation, run composer dump-autoload --optimize for best performance (enables classmap usage without runtime I/O). The core API is simple: \PackageVersions\Versions::getVersion('vendor/package') returns a version string like 1.2.3@abc123, where the suffix is the short commit hash. For the root package name, use \PackageVersions\Versions::rootPackageName() (not the old constant). First use case: injecting version info into application banners or health-check endpoints without hitting Composer’s metadata API at runtime.

Implementation Patterns

Generate static assets during build/deploy using version data — e.g., embed dependency versions in JS/CSS cache-busting filenames, API response metadata, or logging context. Use Versions::getVersion() in services that need version context (e.g., App\Version\VersionInfo factory). Combine with Composer scripts: run a post-install/update dump of version data to JSON/YAML for external tooling or release notes. In CLI commands, fetch and format versions for diagnostic output (php bin/console system:info). Leverage the generated vendor/ocramius/package-versions/src/PackageVersions.php as a reference — though it’s auto-generated, it’s designed to be optimized into classmap and requires no runtime modification.

Gotchas and Tips

  • No runtime IO, but generation depends on composer.lock: versions are baked during install/update; if you forget to commit composer.lock and rebuild in a new environment, the wrong versions may appear. Always deploy with composer.lock.
  • Avoid runtime version checks: the package exists to prevent runtime dependency inspection. Don’t call getVersion() in performance-critical loops or per-request paths (cache or pre-compute instead).
  • Root package name changed in v2: ROOT_PACKAGE_NAME constant was removed — use rootPackageName() method to avoid BC breaks.
  • Autoloading quirks: even with optimize-autoloader, if you skip dump-autoload --optimize (e.g., in CI with --no-dev), expect I/O overhead on first getVersion() call.
  • Debugging versions: inspect composer show -i or composer lock --raw to verify lock-file accuracy. If getVersion() returns unexpected data, check for outdated lock files or manual composer.lock edits.
  • Edge cases: packages installed via path repos or with no git reference may omit the commit hash suffix — versions like 1.0.0 appear as-is.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai