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.
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
This addon current supports the following frameworks:
PRs are welcome to add more frameworks.
-
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
.
To start your framework's REPL environment, simply type the follow:
ddev tinker
-
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
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