phar-io/composer-plugin
Archived proof-of-concept Composer plugin that adds phive:run and phive:info commands to integrate Phive with Composer (e.g., install phar tools like PHPUnit). Unsupported, likely insecure, and may not work with current Composer—do not use in production.
Installation:
Add the plugin to your project’s composer.json under "extra": {"plugins": {"phar-io/composer-plugin": {}}}. Requires Composer ≥1.0.
composer require phar-io/composer-plugin --dev
First Use Case:
Use it to build a PHAR from your project. Create a phar.php script in your project root:
<?php
require __DIR__.'/vendor/autoload.php';
$phar = new Phar(__DIR__.'/myapp.phar');
$phar->startBuffering();
$phar->addFile(__DIR__.'/src/YourClass.php', 'YourClass.php');
$phar->setStub($phar->createStub('index.php'));
$phar->stopBuffering();
Run it via:
php phar.php
Where to Look First:
vendor/phar-io/composer-plugin/src/Phar.php (plugin’s core logic).extra.plugins schema for configuration.Composer Script Integration:
Hook into post-install-cmd or post-update-cmd in composer.json to auto-generate PHARs:
{
"scripts": {
"post-install-cmd": [
"Phar\\build --output=dist/myapp.phar --main=src/index.php"
]
}
}
Use --exclude-vendor to skip vendor dir or --include-vendor to bundle dependencies.
Custom Build Logic:
Extend the plugin by subclassing Phar\Builder:
use Phar\Builder;
use Phar\Builder\Exception\BuildException;
class CustomBuilder extends Builder {
protected function getFiles() {
return [
'src/' => 'src/',
'config/app.php' => 'config/app.php',
];
}
}
Register it in composer.json:
{
"extra": {
"plugins": {
"phar-io/composer-plugin": {
"builder": "CustomBuilder"
}
}
}
}
Dependency Management:
--include-dev to bundle dev dependencies (rare, but useful for dev tools).--exclude-file=tests/*.Stub Customization:
Override the default index.php stub by passing --stub=path/to/custom-stub.php.
Stub File Requirements:
Phar::mapPhar().<?php
Phar::mapPhar();
require 'phar://myapp.phar/index.php';
Filesystem Permissions:
PHP Version Compatibility:
PharData changes).Composer Cache Issues:
composer clear-cache) if builds fail intermittently.--verbose with the plugin to see excluded/included files:
composer phar --verbose
--dry-run to validate file lists without writing.Pre/Post-Build Hooks:
Use Composer’s post-autoload-dump to run custom logic after PHAR generation:
{
"scripts": {
"post-autoload-dump": [
"@php phar-verify.php"
]
}
}
Custom Metadata:
Embed metadata (e.g., version) via Phar::addMetadata() in a post-build script.
Signing PHARs:
Combine with openssl to sign PHARs for distribution:
openssl dgst -sha256 -sign key.pem -out myapp.phar.sig myapp.phar
"extra.plugins"—omitting it will cause silent failures.ClassNotFound errors.How can I help you explore Laravel packages today?