Skip to content

Make php -a history conform to XDG Base Directory Specification #12587

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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

paulfedorow
Copy link

Resolves GH-8546.

To keep existing installations working the code first checks if a history file already exists at ~/.php_history. If it does, then everything works as before.

If ~/.php_history does not exist, we check whether the system supports the XDG Base Directory Specification. If it doesn't we continue using ~/.php_history; otherwise, we use a path that conforms to the XDG Base Directory Specification.

We detect support for XDG Base Directory Specification by checking for environment variables that start with the XDG_ prefix. This is analogous to what Composer does:
composer/composer#1407

The specification can be found here:
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Suggestions on how to implement automated tests for this are welcome. 😸

Resolves phpGH-8546.

To keep existing installations working the code first checks if a
history file already exists at `~/.php_history`. If it does, then
everything works as before.

If `~/.php_history` does not exist, we check whether the system supports
the XDG Base Directory Specification. If it doesn't we continue using
`~/.php_history`; otherwise, we use a path that conforms to the XDG Base
Directory Specification.

We detect support for XDG Base Directory Specification by checking for
environment variables that start with the `XDG_` prefix. This is
analogous to what Composer does:
composer/composer#1407

The specification can be found here:
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
@Seb35
Copy link

Seb35 commented Feb 5, 2024

In my reading of the specification, it would be more appropriate to use $XDG_STATE_HOME:

The $XDG_STATE_HOME contains state data that should persist between (application) restarts, but that is not important or portable enough to the user that it should be stored in $XDG_DATA_HOME. It may contain:

  • actions history (logs, history, recently used files, …)
  • current state of the application that can be reused on a restart (view, layout, open files, undo history, …)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: XDG Base Directory for .php_history
2 participants