php
This directory contains the Talon configuration and behavior overrides that enable comprehensive support for voice-driven development in PHP.
It implements PHP-specific syntax mapping, common programming operators, object-oriented actions, formatters, and custom voice command triggers.
How It Works
The language support is divided into two primary files: 1. php.py manages state, maps standard operator structures, and implements context actions. 2. php.talon activates tags for generalized programming concepts (such as standard comments, boolean logic, and loops), sets standard formatting rules, and maps voice commands.
These components coordinate when Talon detects an active editor with the PHP language context (code.language: php).
File Breakdown
php.py
This Python script handles syntax transformations and defines how standard programming operations translate to PHP syntax:
- Type Map: Registers a predefined list of PHP-specific data types (such as
int,float,string,bool,array,null, andvoid) insideuser.code_typefor quick declaration. - Operators: Instantiates a comprehensive mapping of PHP assignment, math, comparison, and bitwise operators (such as utilizing the strict triple-equals
===and!==for standard comparison, and->for object member access). - Object-Oriented & Logic Implementation: Implements common OOP and logic actions. Examples include:
- Mapping "self" to reference
$this. - Implementing
is_null()andisset()for nullability checks. - Generating boilerplate structures for
public,private, andprotectedmethods (including static variants), formatting method names correctly, and adjusting the text cursor dynamically.
- Mapping "self" to reference
php.talon
This file contains the configuration definitions and active voice command hooks for PHP:
- Talon Tags: Automatically activates the generic interfaces for language-agnostic features like
user.code_imperative,user.code_object_oriented, and various operator tags. This allows generic voice commands (like "state block" or "comment line") to seamlessly use the PHP equivalents. - Naming Conventions: Overrides formatting defaults so that variables, methods, and functions automatically default to camelCase (
PRIVATE_CAMEL_CASE). - Dynamic Variable Insertion: The command
var <phrase>automatically prefixes the output with$and formats the trailing text to match PHP's standard variable style. - Error Handling Statements: Maps
state tryandstate catchto trigger standardized statement snippet insertions.