Tags: #php #composer #local
$PATH~/path/to/your/code/project)$ composer init and select the ‘project’ package type.For debugging use https://github.com/tacnoman/dephpugger (e.g. composer require tacnoman/dephpugger).
You’ll need xdebug too, which has to be installed via pecl and that is only available on PHP when installed via macOS Homebrew.
Also, with latest version of xdebug you’ll find some properties have been updated and so until there is a newer version of dephpugger that supports xdebug 3 you’ll have to manually update vendor/tacnoman/dephpugger/src/Dephpug/Console/CliCommand.php with renamed fields (see https://xdebug.org/docs/errors#CFG-C-CHANGED and the upgrade guide for details).
The summary of those changes being:
- $command = "{$configVar} {$phpPath} -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port={$debuggerPort} -dxdebug.remote_host=127.0.0.1 {$phpFile}";
+ $command = "{$configVar} {$phpPath} -dxdebug.mode=debug -dxdebug.start_with_request=trigger -dxdebug.client_port={$debuggerPort} -dxdebug.client_host=127.0.0.1 {$phpFile}";
Now you can open three shells:
xdebug_break(); where necessary.$ php vendor/bin/dephpugger debugger.cli client: $ php vendor/bin/dephpugger cli main.php.$ cd ~/path/to/local/package
$ git init
$ echo -e "vendor\ncomposer.lock" > .gitignore
$ git add ./
$ git commit -m "Initial Commit"
Ensure the local package’s composer.json file has a name key defined with an appropriate value, as you’ll need to reference that shortly.
Now go back to your project directory and update the composer.json to reference the local package code as a dependency:
{
…
"require": {
"foo/bar": "dev-main"
},
"repositories": [{
"type": "vcs",
"url": "/path/to/local/package"
}]
}
NOTE: The
dev-prefix inside therequireblock denotes a development branch, where typically a semver value (like1.0.0) would otherwise be required.