Skip to content

An addon for DDEV that providers a single command to access a runtime developer console.

License

Notifications You must be signed in to change notification settings

tyler36/ddev-tinker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tests project is maintained

ddev-tinker

What is ddev-tinker?

ddev-tinker is an addon for DDEV that providers a single command to access a runtime developer console.

This addon enables a new command, ddev tinker, that checks which project you are currently in, and runs the correct REPL command for the project.

If you bounce between projects types, this command is really useful.

What is this developer console?

Both Laravel and Drupal have an interactive debugger & REPL environment for tinkering in PHP. You can test various php statements, resolve services or even query the database!

Both environment's are customized versions of the excellent PsySh.

Typically, this console is accessed via:

  • Laravel: php artisan tinker
  • Drupal via a Drush: drush php

*[REPL]: Read-Evaluation-Print-Loop

Supported frameworks

This addon current supports the following frameworks:

PRs are welcome to add more frameworks.

Getting started

  1. Install the addon

    For DDEV v1.23.5 or above run

    ddev add-on get tyler36/ddev-tinker

    For earlier versions of DDEV run

    ddev get tyler36/ddev-tinker

The addon installs globally and will be available to supported framework after running ddev start.

Usage

To start your framework's REPL environment, simply type the follow:

ddev tinker

Arguments

  • ddev tinker can accept simple arguments.

    $ ddev tinker 6+8
    14
  • More complex arguments should be wrapped with '.

     $ ddev tinker 'User::first()'
     [!] Aliasing 'User' to 'App\Models\User' for this Tinker session.
     App\Models\User^ {#4400
     ...
    
     $ ddev tinker 'node_access_rebuild()'
     [notice] Message: Content permissions have been rebuilt.
    
     $ ddev tinker '$node = \Drupal\node\Entity\Node::load(1); print $node->getTitle();'
     Who Doesn’t Like a Good Waterfall?

While this might be helpful for a quick one-off command, it's recommend to run ddev tinker for tinkering to avoid any Docker connection delays between multiple commands.

Wrapping may also work with ", depending on the command used. For more consistent results between frameworks and host OS, it is recommended to use '. See ddev/ddev#2547

Doc command

Out of the box, Psysh contains a doc command that reads "... the documentation for an object, class, constant, method or property".

This add-on downloads the Psysh PHP English manual to the required location for Psysh to find it in the container. For other languages, manually download the file from here, and place it in your project's .ddev/homeadditions/.local/share/psysh folder.

To use the manual, start a session and type doc [FUNCTION_NAME]:

$ ddev tinker
Psy Shell v0.11.13 (PHP 8.1.21 — cli) by Justin Hileman
> doc array_unique
function array_unique(array $array, int $flags = 2): array

Description:
  Removes duplicate values from an array
...

Contributed and maintained by @tyler36 based on the original ddev-contrib recipe by @tyler36