Repository navigation
Add more ways to expose the app version (view helper, endpoint, meta tag, CLI) #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Neluxx
wants to merge
35
commits into
cakephp-5.x
Choose a base branch
from
18-add-more-ways-to-expose-app-version
base: cakephp-5.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
acb56a5
Add AppVersion class as single source of the version
Neluxx 9a5c0be
Add AppVersion view helper with meta tag
Neluxx 80ca634
Add JSON version endpoint controller
Neluxx 69438fa
Fix CS
Neluxx 5732eca
Add app_version CLI command
Neluxx b86f182
Add optional CLI version banner
Neluxx b57699d
Register version endpoint, CLI command and banner in plugin
Neluxx 64d6d60
Document new app version outputs
Neluxx 608a83a
Remove CLI banner listener
Neluxx 488b61a
Rename AppVersionController to VersionController
Neluxx 3a85571
Simplify $version check
Neluxx 6c8182b
Improve usage documentation
Neluxx 2ab4d91
Change path from /version to /app-version
Neluxx e3f6829
Merge remote-tracking branch 'origin/18-add-more-ways-to-expose-app-v…
Neluxx b2632dc
Adjust tests
Neluxx 5668bd1
Rename version to app-version in JSON response
Neluxx 9f508a7
Remove meta.enabled config
Neluxx bbfa621
Update docs/Configuration.md
Neluxx 9760ba4
Update docs/Configuration.md
Neluxx 4392c2d
Merge remote-tracking branch 'origin/18-add-more-ways-to-expose-app-v…
Neluxx 6a6d639
Serve app version endpoint as JSON or HTML depending on extension
Neluxx 8465085
Leave version endpoint routing to the application
Neluxx de0976d
Add getUrlEncoded() to AppVersion helper
Neluxx f415956
Update usage docs and changelog
Neluxx 976f96f
Remove plugin configuration
Neluxx af712e7
Improve documentation
Neluxx 60d0e31
Use the proper coverage annotation
Neluxx 9d74ea9
Fetch the request and view builder once
Neluxx 623e28b
Add AppVersion::extractVersion() to read the version file
Neluxx 9198718
Rename the version endpoint action from index to show
Neluxx 5be5d98
Serve the app version endpoint as XML as well
Neluxx ca88463
Update change log
Neluxx 59af022
Move the security considerations to the usage guide
Neluxx ed4bf89
Update the installation guide for CakePHP 5 and link the guides
Neluxx f9971b3
Improve usage documentation
Neluxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace AppVersion; | ||
|
|
||
| use Cake\Core\Configure; | ||
|
|
||
| /** | ||
| * App Version | ||
| * | ||
| * Central access point for the app version. | ||
| */ | ||
| class AppVersion | ||
| { | ||
| /** | ||
| * The version string to be returned if `App.version` is not set. | ||
| * | ||
| * @var string | ||
| */ | ||
| public const UNKNOWN = 'Unknown'; | ||
|
|
||
| /** | ||
| * The default path of the file containing the app version. | ||
| * | ||
| * @var string | ||
| */ | ||
| public const DEFAULT_VERSION_FILE = ROOT . DS . 'VERSION'; | ||
|
|
||
| /** | ||
| * Get the configured app version. | ||
| * | ||
| * @return string The app version or "Unknown" if it is not set. | ||
| */ | ||
| public static function get(): string | ||
| { | ||
| $version = Configure::read('App.version'); | ||
|
|
||
| if (!$version || !is_scalar($version)) { | ||
| return self::UNKNOWN; | ||
| } | ||
|
|
||
| return (string)$version; | ||
| } | ||
|
|
||
| /** | ||
| * Extract the app version from a version file, e.g. to set `App.version` in `config/bootstrap.php`. | ||
| * | ||
| * Leading and trailing whitespace is removed. | ||
| * | ||
| * @param string $versionFilePath The path of the file containing the app version. | ||
| * @return string The app version or "Unknown" if the file is missing, unreadable or empty. | ||
| */ | ||
| public static function extractVersion(string $versionFilePath = self::DEFAULT_VERSION_FILE): string | ||
| { | ||
| if (!is_file($versionFilePath) || !is_readable($versionFilePath)) { | ||
| return self::UNKNOWN; | ||
| } | ||
|
|
||
| $version = trim((string)file_get_contents($versionFilePath)); | ||
| if ($version === '') { | ||
| return self::UNKNOWN; | ||
| } | ||
|
|
||
| return $version; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.