phpcr/phpcr-shell
Command-line shell for PHPCR repositories. Build and run as a PHAR for easy distribution, and use it to connect to a PHP Content Repository, browse nodes, and execute repository commands. Documentation available on Read the Docs.
## Getting Started
### Minimal Setup
1. **Installation**
```bash
composer require phpcr/phpcr-shell
Ensure your project uses a PHPCR-compatible repository (e.g., Jackalope for Doctrine DBAL-backed repositories). Note for Symfony 8 users: This release explicitly supports Symfony 8 projects.
Basic Usage Run the shell via Artisan (if integrated) or directly:
vendor/bin/phpcr-shell
Authenticate with your repository credentials (configured in .phpcr-shell.ini or via CLI args).
First Use Case List root nodes to inspect repository structure:
ls /
Navigate to a node and query its properties:
cd /path/to/node
get *
Repository Exploration
ls, cd, and pwd to navigate the repository hierarchy.get <property-name> or get * for all.xpath //element(*, nt:folder)
Node Management
setprop to modify properties or mkfile/mkdir to create nodes.
setprop jcr:title "New Title"
mkfile --type nt:file new-file.txt
ls / | xargs -I {} get {} > properties.log).Integration with Laravel/Symfony
phpcr-shell as a custom Artisan command for seamless CLI access:
// app/Console/Commands/PhpcrShellCommand.php
use Symfony\Component\Process\Process;
protected $signature = 'phpcr:shell';
public function handle() {
$process = new Process(['vendor/bin/phpcr-shell']);
$process->run();
$this->output->write($process->getOutput());
}
// src/Command/PhpcrShellCommand.php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
class PhpcrShellCommand extends Command
{
protected static $defaultName = 'app:phpcr-shell';
protected function execute(InputInterface $input, OutputInterface $output): int
{
$process = new Process(['vendor/bin/phpcr-shell']);
$process->run();
$output->write($process->getOutput());
return $process->getExitCode();
}
}
.phpcr-shell.ini per environment (e.g., .phpcr-shell.production.ini).CI/CD Pipelines
Use phpcr-shell in deployment scripts to validate repository state:
vendor/bin/phpcr-shell -f deploy-checks.txt
Example deploy-checks.txt:
xpath count(//jcr:root) > 0 || exit 1
Authentication Quirks
.phpcr-shell.ini are insecure. Use environment variables or Laravel/Symfony’s .env:
[repository]
uri = $REPO_URI
username = $REPO_USER
password = $REPO_PASS
.phpcr-shell.ini to environment-specific files (e.g., .phpcr-shell.staging.ini).Node Type Conflicts
nt:unstructured) may fail silently. Validate types first:
xpath //*[@jcr:primaryType='nt:unstructured']
Performance with Large Repos
get * on deep hierarchies. Use --limit or filter properties:
get jcr:* --limit 100
Session Management
reconnect
Verbose Mode Enable debug output for connection issues:
vendor/bin/phpcr-shell -v
Repository-Specific Errors
jackalope.ini for misconfigurations (e.g., wrong connection strings).vendor/bin/phpcr-shell 2>&1 | tee debug.log
Custom Commands
Extend functionality by creating wrapper scripts (e.g., backup.sh):
#!/bin/bash
vendor/bin/phpcr-shell <<EOF
xpath //*[@jcr:primaryType='nt:file'] | xargs -I {} get {} > backup-$(date +%s).json
EOF
Laravel/Symfony Service Provider
// app/Providers/PhpcrServiceProvider.php
use Symfony\Component\Process\Process;
public function register() {
$this->app->singleton('phpcr.shell', function () {
return new Process(['vendor/bin/phpcr-shell']);
});
}
services.yaml:
services:
app.phpcr.shell:
class: Symfony\Component\Process\Process
arguments: ['vendor/bin/phpcr-shell']
IDE Integration
phpcr-shell in phpstorm.meta.php for autocompletion hints:
return [
'commands' => [
'phpcr-shell' => 'Shell for PHPCR repositories',
],
];
phpcr:// for Jackalope or http:// for remote repositories..phpcr-shell.ini:
[repository]
timeout = 30
composer.json includes Symfony 8 constraints if leveraging Symfony’s new features.
NO_UPDATE_NEEDED would not apply here as the Symfony 8 support warrants updates to the **Implementation Patterns** section, particularly for Symfony users.
How can I help you explore Laravel packages today?