Giter Club home page Giter Club logo

drivers's Introduction

This repository is no longer maintained.

For drivers, please refer to the new beyondcode/tinkerwell repository.

Tinkerwell Drivers

Tinkerwell is an application that lets you run code within your favorite PHP application - either locally or via SSH.

When you open your project with Tinkerwell, one of the available drivers will be loaded and bootstrap your application to prepare it for code execution within Tinkerwell. This repository holds all available drivers for Tinkerwell. So far Tinkerwell supports bootstrapping Laravel and Wordpress applications out of the box. If your framework does not have a specific driver yet, Tinkerwell will at least try and load your projects autoload file.

Installation

Install the Tinkerwell application from https://tinkerwell.app.

Documentation

Anatomy of a driver

Note: The driver name needs to have TinkerwellDriver as a suffix. For example: LaravelTinkerwellDriver, WordpressTinkerwellDriver or CustomTinkerwellDriver

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.

Context menu

Once your application is loaded, Tinkerwell allows you to load custom context menu items that are defined in your driver. Here is an example from a Laravel application:

To define context menu items, add a contextMenu method to your driver. It should return an array of available context menu entries.

use Tinkerwell\ContextMenu\Label;
use Tinkerwell\ContextMenu\Submenu;
use Tinkerwell\ContextMenu\SetCode;
use Tinkerwell\ContextMenu\OpenURL;

public function contextMenu()
{
    return [
        Label::create('Detected Laravel v' . app()->version()),
        
        Submenu::create('Snippets', [
            SetCode::create('Perform Query', '\DB::table("example")->get();'),
        ]);

        OpenURL::create('Documentation', 'https://tinkerwell.app'),
    ];
}

Available context menu items:

Separator

A separator in the context menu.

Separator::create();
Label

A simple label that displays textual information in the context menu:

Label::create('This is the label text');
Link

The OpenURL class can be used to open a specific URL in the browser, once the user clicks on it.

OpenURL::create('Documentation', 'https://tinkerwell.app');
Code Snippets

The SetCode class can be used to automatically pre-fill the Tinkerwell code area with specific code snippets. The code will not automatically be executed.

SetCode::create('Hello World', 'echo "Hello world";');
Submenu

Last but not least you can group multiple context items into a Submenu.

Submenu::create('This is a submenu', [
    Label::create('Entry 1'),
    Label::create('Entry 2'),
    Label::create('Entry 3')
]);

Project specific drivers

You can specify that a project should use a custom Tinkerwell driver, even if it is a project that is already supported by one of the available drivers.

In the project directory that should contain the custom driver, create a .tinkerwell directory. In there you can create your custom Tinkerwell driver class and name it, for example, CustomTinkerwellDriver. Now when you open this project directory within Tinkerwell, your custom driver will be used instead of any built-in drivers.

<?php

use Tinkerwell\ContextMenu\SetCode;

class CustomTinkerwellDriver extends LaravelTinkerwellDriver {

	public function contextMenu(): array
	{
		return array_merge(parent::contextMenu(), [
			SetCode::create('Find latest users', <<<EOT
User::latest()->first()
EOT),
		]);
	}

}

Credits

License

The MIT License (MIT). Please see License File for more information.

drivers's People

Contributors

aaronredwood avatar andrewgatenbyvs avatar beebmx avatar braunson avatar danielfatkic avatar earnjam avatar edalzell avatar ilyahoilik avatar jasonvarga avatar konafets avatar maks-rafalko avatar marcomessa avatar markdrzy avatar mechelon avatar michielgerritsen avatar mlanth avatar mpociot avatar naoray avatar owenvoke avatar sschlein avatar terrorboy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

drivers's Issues

Custom crypto binding not available - Can't connect to remove server

For our works development environments, we're using Coder.com and it aliases connections as coder.workspacename so if I have a workspace called example, in any terminal on my machine I can type ssh coder.example and connect just fine.

This also works in TablePlus, SQL Pro Studio, VS Code, etc.

When I try to tell Tinkerwell to connect to a domain like this, it throws the following error:

Custom crypto binding not available
Local ident: 'SSH-2.0-ssh2js1.10.0'
Client: Trying coder.example on port 22 ...
Socket error: getaddrinfo ENOTFOUND coder.example

These servers are used to run remote Laravel development environments so being able to connect to them with Tinkerwell would be greeeeeat.

Where can I store "global" drivers?

I would like to create a global driver which is available in any Laravel application. This drive will ultimately want to create files in the current project directory.

This driver will be very similar to the Artisan driver, but instead it will work with our Laraval Craftsman utility.

Latest symfony version driver

The latest version of Symfony doesn't have bootstrap.php
and the project cannot be recognized as Symfony project because of this:

file_exists($projectPath . '/config/bootstrap.php')

Unable to connect to local Valet WordPress site.

It's not a standard WP installation. We use Composer to pull in WP as a dependency. The installation is similar to what's described here.

The app is throwing this warning.

The path to composer's vendor directory is wp-content/vendor/autoload.php.

I upgraded to Version 2.2.0 (2.2.0) just now but that didn't help. Also running the latest version of MacOS, 10.15.3. Laravel Valet is up to date as well.

Any suggestions? Thanks in advance.

Lumen Driver not working for me

Hello guys, Im still new using Tinkerwell. It works well in Laravel App, but in Lumen its a bit weird.

For example: If I tried to used Eloquent to get first data in modal. I did not get the data instead I only get the properties of the modal Image of Yaktocat.

For second problem is, In Laravel app, If I tried to open query inspection(Ctrl + Shift + R) I got this error Image of Yaktocat

Im using on Windows.

Craft environment loading fails on old Craft 3 installations

Craft installations previous to version 3.2 (and projects upgraded from those installations) used version 2 of the vlucas/phpdotenv package. Version 2 of this package used a different method for loading environment files, and the current Craft driver fails with the following error:

PHP Fatal error:  Uncaught Error: Call to undefined method Dotenv\Dotenv::create() in phar:///Applications/Tinkerwell.app/Contents/Resources/tinkerwell/tinker.phar/src/Drivers/CraftTinkerwellDriver.php:28
Stack trace:
#0 phar:///Applications/Tinkerwell.app/Contents/Resources/tinkerwell/tinker.phar/index.php(26): CraftTinkerwellDriver->bootstrap('/Users/mdrzycim...')
#1 /Applications/Tinkerwell.app/Contents/Resources/tinkerwell/tinker.phar(14): require('phar:///Applica...')
#2 {main}
  thrown in phar:///Applications/Tinkerwell.app/Contents/Resources/tinkerwell/tinker.phar/src/Drivers/CraftTinkerwellDriver.php on line 28

Table mode, support for ArrayObject / ArrayAccess?

Hi,
I'm working on a custom driver for a non-laravel project.
It's models return collections which implement ArrayObject.
Currently the table mode doesn't seem to support these & to get around this I'm converting to an array in tinkerwell each time.
It'd be great if either the table mode supported these out of the box, or is there a way I can add support for them via the drivers?

Thank you.

How to test/debug local drivers?

I've created .tinkerwell/MyCustomTinkerwellDriver.php on my project but doesn't appear to load.

  • There is an "official" way to locally test drivers before PR?
  • There is any way to debug drivers?

`contextMenu()` is ignored in custom driver

With the following code:

final class InfectionTinkerwellDriver extends TinkerwellDriver
{
    public function canBootstrap($projectPath)
    {
        var_dump('canBootstrap');

        return file_exists($projectPath . '/bin/infection');
    }

    public function bootstrap($projectPath)
    {
        var_dump('bootstrap');
        require_once $projectPath . '/vendor/autoload.php';
    }

    public function getAvailableVariables()
    {
        var_dump('getAvailableVariables');
        return [
            'container' => Container::create(),
        ];
    }

    public function contextMenu()
    {
        var_dump('Detected Infection');
        return [
            Label::create('Detected Infection'),
        ];
    }
}

when I run the empty script on Tinkerwell, it get:

Tinkerwell - infection 2020-01-26 02-00-27

So you can see that contextMenu is ignored and I don't see any new context menu items in the app.

Allow CustomTinkerwellDriver to declare custom VarDumper Casters

It would be great if a custom Tinkerwell driver could declare custom casters, Tinkerwell's abstract class could have a getCasters method that would return an array with a casters key as expected by PsySH. Something like:

abstract public function getCasters ();

Proper execution of `Artisan` code?

I am trying out the Artisan driver, for example using the env command

Artisan::call('env', []);
Artisan::output();

When code is executed in Tinkerwell, the following is output

/Users/mikee/Documents/code/honu.salon/.tinkerwell/CustomTinkerwellDriver.php:10:
string(51) "canBootstrap /Users/mikee/Documents/code/honu.salon"
�[43mPHP Deprecated:  Return value of "Illuminate/Foundation/Console/EnvironmentCommand::execute()" should always be of the type int since Symfony 4.4, NULL returned. in /Users/mikee/Documents/code/honu.salon/vendor/symfony/console/Command/Command.php on line 258�[49m
=> "Current application environment: local\n"

So far as I can tell, I should receive the standard Artisan output as if it was entered in console

~/Documents/code/honu.salon master*
❯ php artisan env              
Current application environment: local

Custom modes

What are your thoughts on a way for drivers to add custom mode options?

Ones like the HTTP mode where you have a controller and view would be especially useful.

Here's a use case, I have Twig templates and a simple system for controllers, If the drivers offered a way to add custom modes, I could hook up a simple way to run code as if in an controller and then a twig file as the view to test out changes quickly, could be really awesome :)

Awesome work on the app already btw 👍

Cascaded driver loading?

I think there is a possible issue with how driver's are loaded?

I'm attempting to load a Lumen project, but it seems to be attempting to load it as a Laravel application.

I get the following error.

In LaravelTinkerwellDriver.php line 24:
                                                                             
  Call to undefined method App\Console\Kernel::bootstrap()  

I'm not sure how drivers are loaded exactly or how the driver is determined beyond what I see in the existing code, but a Lumen application fits the parameters of canBootstrap() for both LaravelTinkerwellDriver and LumenTinkerwellDriver and since Laravel comes before Lumen alphabetically, it's my guess that it attempts to load LaravelTinkerwellDriver, and then fails, and doesn't have anyway to try the next driver.

  • Is driver loading cascaded at all if it fails to load one, and will attempt to load another if it fits?
  • Is there anyway to force a specific driver?

Basic keyboard input not working on left (nor right) pane of freshly installed app.

Just bought and installed the app for the first time.

No idea what configuration is supposed to be needed for this but I cannot type in neither left nor right pane of the app.

I have tried with "default" as well as with a project loaded from WSL.

Right-click and selecting artisan commands works though. Select a command once, and the code snippet is pasted into left pane window. Select a command a second time, and the contents of the left pane window are completely replaced by the snippet behind the selected artisan command.

Having artisan snippet in place, I can put mouse cursor anywhere, highlight text, and copy it. But I cannot paste or type anything.

I can type anywhere in any other app (where text is expected) except in Tinkerwell.

What could be a possible culprit?

Tinkerwell version: 2.25.0
DEVICE:
Processor Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz 3.60 GHz
Installed RAM 16,0 GB
System type 64-bit operating system, x64-based processor
Pen and touch No pen or touch input is available for this display
WINDOWS:
Edition Windows 10 Pro
Version 21H2
Installed on ‎28. ‎10. ‎2021
OS build 19044.1620
Experience Windows Feature Experience Pack 120.2212.4170.0

SetCode `insert` method

In reviewing the SetCode class methods, I only see the ability to create code, which overwrites the entire code area. Is there the ability to insert code at the current cursor position?

Example

SetCode::insert("codeToAdd");

Or further, get the highlighted code and replace with new code

SetCode::replace("codeToReplace");

Not working with php 5.6.40

By setting the version of php 5.6.40 the app no longer works, I would need to create a driver for vtiger 6 that does not support php 7 but I can't.
In the documentation I did not find any reference on the minimum php version required, after all I also wanted to point out that the link to the faq from the application refers to the homepage but I could not find the faq.

[Feature request] "public_html" support

In some hosting environments public_html is used instead of public.

Currently, the public folder is hard-coded in the Laravel driver:
https://github.com/tinkerwellapp/drivers/blob/master/src/Drivers/LaravelTinkerwellDriver.php#L12

So at this moment for these projects, Tinkerwell can not be used without writing a custom driver for the projects that have a public_html folder.

Possible fixes:

  • Only check for the existence of artisan and ignore the webroot folder.
  • Check for both public and public_html
  • ...

For now there is a work-around by including a custom driver that is a copy of the Laravel driver and has the path changed, but it is my opinion extra overhead, dirties repo's and should be working out-of-the-box.

`InsertCode` context menu item

Currently there's the SetCode context menu item.

public function contextMenu()
{
	return [
   		SetCode::create('Create a sum', 'echo 1 + 1;');
   	];
}

SetCode wipes the current editor's code and replaces it with the relevant snippet.

It would also be useful to have an InsertCode context menu item, that works in the same way, but instead inserts the snippet at the cursor's current position.

public function contextMenu()
{
	return [
   		InsertCode::create('Create a sum', 'echo 1 + 1;');
   	];
}

I would have sent a pull request, but I'm assuming this requires integration in the Electron project, which is closed source. 😃

Custom Drivers Require the name "TinkerwellDriver.php" to load

In the documentation it makes no mention of the suffix of TinkerwellDriver.php but in the code of tinkerwelldriver.php it becomes apparent to load a driver you need to call you driver
xxxx-TinkerwellDriver.php

Because of this line

$regex = new RegexIterator($iterator, '/^.+TinkerwellDriver\.php$/i', RecursiveRegexIterator::GET_MATCH);

Im not sure if you want to clarify this in the readme or allow the loading of *Driver.php

Inclusion of `bootstrap` method throws error

I am testing a very simple driver, and when I include the bootstrap method, it causes an error when loading custom project.

image

If I remove the bootstrap method, everything works as expected.

The simple driver code (basically pulled from example below)

<?php

use Tinkerwell\ContextMenu\SetCode;

class CustomTinkerwellDriver extends LaravelTinkerwellDriver
{

    public function canBootstrap($projectPath)
    {
        var_dump("canBootstrap ${projectPath}");
        return true;
    }

    // if function is removed, all works as expected
    public function bootstrap($projectPath)
    {
    }

    public function contextMenu(): array
    {
        return array_merge(parent::contextMenu(), [
            SetCode::create('Find latest users', <<<EOT
User::latest()->first()
EOT
            ),
        ]);
    }

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.