Skip to content

Commit 9e9dd73

Browse files
committed
docs: add comprehensive development guide for phpvm
1 parent 614bdeb commit 9e9dd73

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

CLAUDE.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# CLAUDE.md - phpvm Development Guide
2+
3+
## Project Overview
4+
5+
**phpvm** is a lightweight PHP Version Manager for macOS and Linux that enables easy installation, switching, and management of multiple PHP versions via command line. The project is built as a single, comprehensive bash script with extensive cross-platform compatibility.
6+
7+
## Architecture
8+
9+
### Core Components
10+
11+
- **`phpvm.sh`** - Main functionality (1000+ lines of bash)
12+
- PHP version installation and management
13+
- Cross-platform package manager detection
14+
- Version switching with symlink management
15+
- Auto-switching based on `.phpvmrc` files
16+
- Built-in comprehensive test suite
17+
18+
- **`install.sh`** - Installation script
19+
- Downloads and sets up phpvm
20+
- Configures shell profile integration
21+
- Handles different shell types (bash/zsh)
22+
23+
- **`versions/`** - Directory for PHP version metadata (currently empty)
24+
25+
### Package Manager Support
26+
27+
The tool detects and works with multiple package managers:
28+
- **macOS**: Homebrew (`brew`)
29+
- **Linux**: apt, dnf, yum, pacman
30+
- **Linuxbrew**: Supported on Linux systems
31+
32+
## Key Functionality
33+
34+
### Version Management
35+
- Install PHP versions using system package managers
36+
- Switch between installed versions using symlinks and package manager tools
37+
- System PHP fallback support
38+
- Active version tracking via `~/.phpvm/active_version`
39+
40+
### Auto-Switching
41+
- Detects `.phpvmrc` files in current/parent directories (up to 5 levels)
42+
- Automatically switches to specified PHP version
43+
- Handles corrupted/invalid `.phpvmrc` files gracefully
44+
45+
### Testing Framework
46+
- Built-in self-tests (`phpvm test`)
47+
- Mock environment creation for testing
48+
- Comprehensive test coverage including edge cases
49+
- No external testing dependencies required
50+
51+
## Development Guidelines
52+
53+
### Code Style
54+
- POSIX-compliant bash scripting where possible
55+
- Comprehensive error handling with structured logging
56+
- Timestamped log messages with levels (INFO, ERROR, WARNING, DEBUG)
57+
- Helper functions to reduce code duplication
58+
59+
### Testing
60+
- Run tests: `./phpvm.sh test`
61+
- Tests create isolated mock environments
62+
- All core functionality is tested including error conditions
63+
- Tests verify cross-platform compatibility
64+
65+
### Debugging
66+
- Enable debug mode: `DEBUG=true phpvm <command>`
67+
- Debug logs provide detailed execution tracing
68+
- Test mode can be enabled with `PHPVM_TEST_MODE=true`
69+
70+
## Common Development Tasks
71+
72+
### Adding New Commands
73+
1. Add command handler in the `main()` function case statement
74+
2. Implement the command function following naming convention `command_name()`
75+
3. Add help text in `print_help()`
76+
4. Add tests in the `run_tests()` function
77+
78+
### Supporting New Package Managers
79+
1. Add detection logic in `detect_system()`
80+
2. Add installation logic in `install_php()`
81+
3. Add version switching logic in `use_php_version()`
82+
4. Add version listing logic in `list_installed_versions()`
83+
5. Add uninstall logic in `uninstall_php()`
84+
85+
### Testing Changes
86+
```bash
87+
# Run all tests
88+
./phpvm.sh test
89+
90+
# Enable debug mode for troubleshooting
91+
DEBUG=true ./phpvm.sh test
92+
93+
# Test specific functionality manually
94+
DEBUG=true ./phpvm.sh install 8.1
95+
DEBUG=true ./phpvm.sh use 8.1
96+
```
97+
98+
### Release Process
99+
1. Update version number in `PHPVM_VERSION` variable
100+
2. Update CHANGELOG.md with new features/fixes
101+
3. Test across different platforms
102+
4. Ensure all tests pass
103+
5. Update README.md if needed
104+
105+
## File Structure
106+
107+
```
108+
phpvm/
109+
├── CLAUDE.md # This file
110+
├── CHANGELOG.md # Release history
111+
├── LICENSE # MIT license
112+
├── README.MD # User documentation
113+
├── TESTING.md # Testing documentation (minimal)
114+
├── assets/ # Project images
115+
├── install-bats.sh # BATS installation script
116+
├── install.sh # Main installation script
117+
├── phpvm.sh # Core functionality
118+
└── versions/ # Version metadata directory
119+
```
120+
121+
## Environment Variables
122+
123+
- `PHPVM_DIR` - Installation directory (default: `~/.phpvm`)
124+
- `DEBUG` - Enable debug logging (set to `true`)
125+
- `PHPVM_TEST_MODE` - Enable test mode (set to `true`)
126+
- `PHPVM_SOURCED` - Control execution vs sourcing behavior
127+
- `PHPVM_AUTO_USE` - Enable automatic `.phpvmrc` detection (default: `true`)
128+
129+
## Cross-Platform Considerations
130+
131+
### macOS Specifics
132+
- Relies on Homebrew for PHP installation
133+
- Uses `brew link/unlink` for version switching
134+
- Handles Homebrew prefix detection automatically
135+
136+
### Linux Specifics
137+
- Supports multiple package managers
138+
- Uses `update-alternatives` for version switching where available
139+
- Requires `sudo` privileges for system-level operations
140+
141+
### Shell Compatibility
142+
- Works with bash and zsh
143+
- POSIX-compliant where possible
144+
- Handles different shell profile files (.bashrc, .zshrc, .profile)
145+
146+
## Security Considerations
147+
148+
- Uses `run_with_sudo()` helper for controlled privilege escalation
149+
- Validates input parameters before system operations
150+
- No hardcoded credentials or sensitive data
151+
- Safe handling of temporary files and directories
152+
153+
## Performance Notes
154+
155+
- Lightweight single-script architecture
156+
- Minimal external dependencies
157+
- Fast execution due to bash implementation
158+
- Efficient directory traversal for `.phpvmrc` detection

0 commit comments

Comments
 (0)