VOOZH about

URL: https://deepwiki.com/friendsofhyperf/components/10.1-tinker-and-web-tinker

⇱ Tinker and Web Tinker | friendsofhyperf/components | DeepWiki


Loading...
Last indexed: 14 February 2026 (15d5ca)
Menu

Tinker and Web Tinker

Purpose and Scope

This document covers the Tinker and Web Tinker components, which provide interactive REPL (Read-Eval-Print-Loop) interfaces for debugging and experimenting with Hyperf applications. Tinker offers a command-line shell powered by PsySH, while Web Tinker extends this functionality to a browser-based interface for remote debugging.

For information about other development tools, see IDE Helper and Code Generation. For testing infrastructure, see Testing Infrastructure.


Overview

The Tinker component integrates PsySH (PHP REPL) into Hyperf, providing an interactive shell for executing PHP code, inspecting objects, exploring the application state, and testing code snippets without creating temporary scripts. Web Tinker wraps this functionality in a web interface, enabling browser-based access to the same REPL capabilities.


Diagram: Tinker and Web Tinker Architecture

The REPL provides full access to the application's DI container, models, services, and helper functions, enabling interactive exploration and debugging of the running application.

Sources: composer.json1-331 src/tinker/composer.json1-56


Tinker REPL (Command-Line Interface)

Component Structure

The Tinker component registers a console command that launches an interactive PsySH shell within the Hyperf application context. This shell provides tab completion, history, syntax highlighting, and extensive introspection capabilities.


Diagram: Tinker Command-Line Architecture

Sources: src/tinker/composer.json26-35 composer.json295

Dependencies and Integration

The Tinker component relies on several key dependencies:

DependencyVersionPurpose
psy/psysh^0.10.0 || ^0.11.0 || ^0.12.0Core REPL engine
hyperf/command~3.1.0Command registration
hyperf/di~3.1.0Dependency injection access
hyperf/collection~3.1.0Collection helpers in REPL
hyperf/stringable~3.1.0String manipulation
hyperf/support~3.1.0Foundation utilities
hyperf/tappable~3.1.0Fluent interface support

Sources: src/tinker/composer.json26-35

ConfigProvider Registration

The component uses Hyperf's ConfigProvider pattern for automatic registration:


Diagram: Tinker ConfigProvider Registration Flow

The ConfigProvider class exports a commands array that Hyperf automatically discovers and registers during application bootstrap. This enables the php bin/hyperf.php tinker command without manual configuration.

Sources: src/tinker/composer.json52-54 composer.json295

Custom Casters

Tinker supports custom casters for displaying Hyperf-specific objects in a readable format within the REPL. These casters transform complex objects into formatted output.


Diagram: Custom Caster System

Casters are registered with PsySH during shell initialization, enabling intelligent display of Hyperf objects. For example, Eloquent models show their attributes and relations, while collections display their items in a structured format.

Sources: src/tinker/composer.json37-38

Usage Patterns

Common Tinker usage patterns include:

Interactive Model Queries:


Testing Helper Functions:


Exploring Collections:


Accessing Context:


Sources: src/tinker/composer.json26-35


Web Tinker (Browser Interface)

Architecture

Web Tinker provides an HTTP-based interface to the Tinker REPL, allowing developers to execute PHP code through a web browser. This is particularly useful for remote debugging or environments where console access is restricted.


Diagram: Web Tinker HTTP Request Flow

Sources: composer.json167 composer.json298

Component Dependencies

Web Tinker builds on top of the Tinker component and adds HTTP-specific functionality:


Diagram: Web Tinker Dependency Graph

The Web Tinker component reuses the core Tinker shell execution logic but wraps it in an HTTP controller, providing route registration and browser UI.

Sources: composer.json164 composer.json167 composer.json298

Security Considerations

Web Tinker provides arbitrary code execution capabilities and should be protected in production environments:


Diagram: Web Tinker Security Flow

Best Practices:

Security ControlImplementationPurpose
Environment CheckDisable in production via configPrevent exposure in prod
AuthenticationRequire login credentialsUser verification
IP WhitelistRestrict to specific IPsNetwork-level access control
Rate LimitingThrottle execution requestsPrevent abuse
CSRF ProtectionToken validationPrevent cross-site attacks
Input SanitizationValidate code inputBasic injection prevention

Sources: composer.json298

User Interface

Web Tinker provides a browser-based code editor with syntax highlighting and output display:


Diagram: Web Tinker UI Components

The interface typically includes:

  • A code editor with syntax highlighting for PHP
  • An output area displaying execution results
  • Execute and clear buttons
  • Command history for quick access to previous inputs

Sources: composer.json167 composer.json298


Configuration and Setup

Installation

Install Tinker for command-line REPL:


Install Web Tinker for browser-based REPL:


Both components auto-register via their ConfigProvider classes.

Sources: composer.json164 composer.json167 composer.json295 composer.json298

Configuration Files

Configuration options are managed through Hyperf's config system:


Diagram: Configuration Structure

Configuration files can be published using:


Sources: composer.json295 composer.json298

Environment Detection

The components respect Hyperf's environment settings:

EnvironmentTinker CLIWeb Tinker
devEnabledEnabled
testingEnabledDisabled (default)
productionEnabledDisabled (default)

Web Tinker should be explicitly disabled in production environments or protected behind strong authentication.

Sources: composer.json298


Integration with Development Workflow

Usage in Development

Tinker integrates into the standard Hyperf development workflow:


Diagram: Tinker in Debug Workflow

Common debugging scenarios:

  • Testing database queries before implementing them
  • Inspecting model relationships and attributes
  • Verifying service method behavior
  • Testing API client requests
  • Exploring collection transformations

Sources: src/tinker/composer.json1-56

Integration with Other Tools

Tinker complements other development tools in the friendsofhyperf ecosystem:


Diagram: Tinker in Development Toolchain

For automated testing, see Testing Infrastructure. For IDE support, see IDE Helper and Code Generation. For request monitoring, see Telescope Debug Assistant.

Sources: composer.json295 composer.json298 README.md69-73


Advanced Features

Custom Casters for Hyperf Types

Custom casters enable readable display of complex Hyperf objects:


Diagram: Custom Casters for Hyperf Types

Casters transform internal object representations into developer-friendly output, making it easier to understand object state during interactive debugging.

Sources: src/tinker/composer.json37-38

HtmlString Support

The Tinker component integrates with hyperf/view-engine to support HtmlString objects:


Diagram: HtmlString Caster Integration

When hyperf/view-engine is installed, Tinker automatically registers casters for HtmlString objects, displaying them appropriately in the REPL.

Sources: src/tinker/composer.json37-38


Comparison: CLI vs Web Interface

FeatureTinker (CLI)Web Tinker
Access MethodCommand lineWeb browser
AuthenticationOS-level (terminal access)HTTP auth required
PerformanceNative PHP executionHTTP overhead
HistoryReadline/PsySH historyBrowser-based history
Syntax HighlightingTerminal-basedJavaScript-based
Tab CompletionFull PsySH completionLimited/none
Multi-line InputNative supportJavaScript editor
Security RiskTerminal access onlyHTTP exposure
Remote AccessSSH requiredDirect HTTP access
Production UseSafe (if terminal secured)Not recommended

Comparison Table: Tinker CLI vs Web Tinker

Recommendations:

  • Use Tinker CLI for local development and SSH-accessible servers
  • Use Web Tinker only in development environments or with strong authentication
  • Never expose Web Tinker on production servers without comprehensive security controls

Sources: src/tinker/composer.json1-56 composer.json167


Troubleshooting

Common Issues

Issue: Tinker command not found

  • Verify installation: composer show friendsofhyperf/tinker
  • Check ConfigProvider is loaded in Hyperf's config system
  • Ensure hyperf/command is installed

Issue: Web Tinker returns 404

  • Verify Web Tinker is installed
  • Check route registration in application
  • Ensure HTTP server is running

Issue: Code execution fails in Tinker

  • Verify syntax is correct (PsySH enforces strict syntax)
  • Check that required classes/functions are loaded
  • Ensure DI container has required bindings

Issue: Web Tinker access denied

  • Check authentication middleware configuration
  • Verify IP whitelist if configured
  • Review environment settings (disabled in production)

Sources: src/tinker/composer.json26-35


Related Components

Tinker and Web Tinker integrate with other friendsofhyperf development tools:

Sources: README.md69-73 composer.json164 composer.json167