Skip to content
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

Helper Functions to Manage php.ini Entries #1420

Closed
adamziel opened this issue May 17, 2024 · 1 comment
Closed

Helper Functions to Manage php.ini Entries #1420

adamziel opened this issue May 17, 2024 · 1 comment

Comments

@adamziel
Copy link
Collaborator

I wrote this issue using chatgpt voice transcription, there are some inaccuracies I'll polish later.

Description

We need to add helper functions to manage php.ini entries.

Let's remove php.setPhpIniEntry and php.setPhpIniPath to keep the PHP module api small.

Details

Default php.ini Path

  • PHP should load a php.ini file from /internal/shared/php.ini.
  • This path should be set in the C module during PHP runtime initialization.
  • There should be no exported C methods to customize this path or to overwrite in-memory PHP INI entries. All entries should be loaded from the php.ini file.
  • The php.ini file should have precedence over any defaults provided in the C code.

Exported Helper Methods

We need to implement the following helper methods to manage php.ini entries:

  1. set.php.ini.entry: Set a specific php.ini entry.

    • Parameters:
      • entry (string): The php.ini entry to set.
      • value (string): The value to set for the entry.
    • Example: set.php.ini.entry('memory_limit', '256M');
  2. set.php.ini.entries: Set multiple php.ini entries.

    • Parameters:
      • entries (object): An object where keys are php.ini entries and values are the respective values to set.
    • Example: set.php.ini.entries({ 'memory_limit': '256M', 'upload_max_filesize': '64M' });
  3. get.php.ini.entry: Get a specific php.ini entry.

    • Parameters:
      • entry (string): The php.ini entry to retrieve.
    • Returns:
      • value (string): The value of the specified php.ini entry.
    • Example: get.php.ini.entry('memory_limit'); // Returns '256M'

Internal Utility Functions

To support these helper methods, we need to implement internal utility functions to parse .ini files and serialize them:

  1. parseIniFile: Convert a .ini file to JSON.

    • Parameters:
      • filePath (string): Path to the .ini file.
    • Returns:
      • json (object): JSON representation of the .ini file.
    • Example: parseIniFile('./.internal/.shared/.php.ini');
  2. serializeIniFile: Convert JSON to a .ini file.

    • Parameters:
      • json (object): JSON object representing the .ini configuration.
      • filePath (string): Path where the .ini file should be saved.
    • Example: serializeIniFile(jsonConfig, './.internal/.shared/.php.ini');

Tasks

  1. Implement the set.php.ini.entry method.
  2. Implement the set.php.ini.entries method.
  3. Implement the get.php.ini.entry method.
  4. Implement the parseIniFile utility function.
  5. Implement the serializeIniFile utility function.
  6. Write tests for each of the helper methods and utility functions.

Notes

  • Ensure that the php.ini file is always loaded from the fixed path (./.internal/.shared/.php.ini).
  • The path should be set in the C module during PHP runtime initialization.
  • There should be no exported C methods to customize the path or to overwrite in-memory PHP INI entries.
  • Ensure that the php.ini file has precedence over any defaults provided in the C code.
  • The internal utility functions should handle errors gracefully, such as file not found or invalid JSON/INI format.

This feature will enhance the configurability of PHP within the WordPress Playground and simplify the management of php.ini settings.

@adamziel
Copy link
Collaborator Author

Closed in #1423

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

No branches or pull requests

2 participants
@adamziel and others