Tinkerwell

Custom drivers

A Tinkerwell driver is a simple class that will be called when your project gets opened in the Tinkerwell application.
Here is how a basic driver for Wordpress looks like:

class MyCustomTinkerwellDriver extends TinkerwellDriver
{
    /**
     * Determine if the driver can be used with the selected project path.
     * You most likely want to check the existence of project / framework specific files.
     *
     * @param  string $projectPath
     * @return  bool
     */
    public function canBootstrap($projectPath)
    {
        return file_exists($projectPath . '/wp-load.php');
    }
    
    /**
     * Bootstrap the application so that any executed can access the application in your desired state.
     * 
     * @param  string $projectPath
     */
    public function bootstrap($projectPath)
    {
        require $projectPath . '/wp-load.php';
    }
}

The canBootstrap and bootstrap methods are the important pieces of every driver. They determine if the driver can be used for the given project path and how the application should get bootstrapped and prepared, so that the application is in the correct state when any code gets executed.

Providing variables#

When a Tinkerwell driver gets loaded, you can tell Tinkerwell to automatically set variables with specific content, so that these variables are immediately available within the Tinkerwell application.

To define these variables, add a getAvailableVariables to your driver. This method should return an array of all variables and their values:

public function getAvailableVariables()
{
    return [
        '__blog' => get_bloginfo()
    ];
}

This method gets executed after the Tinkerwell drivers bootstrap method was called, so that you have access to any classes that got bootstrapped along with the driver.

Using a custom driver in an existing project#

If you want to use your custom Tinkerwell driver in an existing project, create a folder called .tinkerwell in the application directory where you want to customize the context menu.

Then you can create a new file called CustomTinkerwellDriver.php. This file should now contain the custom driver that you want to use.

If you feel like your custom driver might be useful for others, for example if you add support for a commonly used framework or PHP application, please consider sending the custom driver as a pull request to the Tinkerwell Drivers repository so that everyone can benefit from the driver in the future.