TweakPHP Documentation

website·Indexed 31 days ago

https://tweakphp.com

A cross-platform desktop application and open source PHP playground featuring a code editor to tweak PHP code. It supports various connection methods including SSH, Docker, Kubernetes, and Vapor, and provides a client library and custom loaders for extending functionality.

Tokens
3.1K
Snippets
6
Records
37
Agent score
54%

What's inside TweakPHP

  1. Overview of TweakPHP functionality

    TweakPHP is a desktop application featuring a code editor designed to execute PHP code within the context of a project. It uses a bundled client PHP package to run code and automatically recognizes the project framework to handle bootstrapping. For example, in a Laravel project, it automatically includes vendor/autoload.php and bootstraps the application before executing the user's code.
  2. Overview of TweakPHP PHP Playground

    TweakPHP is a cross-platform desktop application for testing and running PHP code. It provides a Monaco-powered editor (the same engine as VS Code) with syntax highlighting and IntelliSense. It is designed for rapid iteration, allowing developers to write and run PHP code with real-time output across various environments.
  3. Understand the TweakPHP Client Library

    TweakPHP utilizes a dedicated PHP client library to load PHP projects and execute code within them. The library is open-source and available on GitHub.
  4. Understand how TweakPHP executes code

    TweakPHP utilizes a bundled client library packaged into phar files. It employs various loaders tailored to the specific framework of your project to load the project environment and execute the provided code within that context.
  5. Bootstrap PHP projects using TweakPHP Loaders

    The TweakPHP client library provides specialized loaders to bootstrap different types of PHP applications. Supported loaders include:

    • Laravel
    • Symfony
    • WordPress
    • Any standard Composer project (supported out of the box)
  6. Run code in the TweakPHP editor

    Once a project is open, you can execute code written in the editor using the following keyboard shortcuts. The execution results are displayed in the read-only editor on the left side of the screen.
    # macOS
    Command + R
    
    # Other Operating Systems
    Ctrl + R
  7. Propose features and discuss development

    New features or improvements should be proposed via the GitHub Discussion Board. Contributors proposing new features are expected to implement at least a portion of the required code. Informal discussions regarding bugs and features occur in the #ideas channel of the TweakPHP Discord server. Note: Do not refactor existing code without prior discussion with maintainers.
  8. Connect TweakPHP to different PHP environments

    TweakPHP allows you to execute code across multiple target environments to ensure flexibility in testing and development. Supported connection types include:

    • Local Projects: Run code directly on local PHP projects with automatic framework detection.
    • Docker Support: Execute code inside isolated Docker containers.
    • SSH Connections: Run code on remote servers via SSH.
    • Laravel Vapor: Connect to Vapor environments for serverless PHP execution.
  9. Find and claim tasks for contribution

    New contributors are encouraged to start with open issues in the Todo state, which are sorted by priority. To claim a task, pick an unassigned issue from the project board and leave a comment to be officially assigned.
  10. Execute PHP code in a Laravel Vapor environment using TweakPHP

    TweakPHP allows you to run PHP code directly within a Laravel Vapor environment by leveraging the vapor tinker cli. This ensures code is executed with the same runtime, services, and configuration as your deployed serverless infrastructure.

    Requirements: Your project must contain a valid vapor.yml file at the root for TweakPHP to detect available environments.

    Execution Steps:

    1. Select the target environment from the environment selection dropdown (populated automatically from vapor.yml).
    2. Write PHP code in the editor. You do not need to include <?php or ?> tags.
    3. Execute the code by clicking Run or using the keyboard shortcut Command+R (macOS) or Ctrl+R (Windows/Linux).

    Important Constraints:

    • Production Risk: There are no safety checks. Selecting a production environment will execute code directly in production.
    • Disabled Features: Stack trace visualization and custom loaders are not supported when running in Vapor environments.
  11. Activate and use a custom loader

    To use a created loader: Navigate to your project and select the desired loader from the top toolbar. Once selected, the editor's status bar will update to show the loader's name and version. When the code is executed, the logic inside the loader's constructor runs first.