meyfa/php-svg
Lightweight PHP library to create, read, and manipulate SVGs. Build SVG documents programmatically, edit shapes and attributes via a DOM-like API, and export clean SVG/XML. Handy for generating icons, diagrams, and server-side graphics without external dependencies.
array_unpack for attribute handling).enum support (if extended in future versions) to create type-safe SVG theme configurations.Fiber support could enable non-blocking SVG generation for high-concurrency APIs (e.g., real-time dashboards).php-svg v3.x) without rewriting Blade templates or API routes.string $id instead of mixed).readonly public string $namespace).create_function in custom SVG logic).^0.16 in composer.json to avoid unintended major version bumps.<path> data). Mitigate with Laravel’s app()->bind() for custom error handlers.array_is_list() to validate SVG element structures in unit tests.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| PHP Version Lock-in | Medium | Require PHP 8.4+ in phpstan.neon and composer.json to enforce consistency. Use Laravel’s bootstrap/app.php to validate runtime PHP version. |
| Undisclosed Breaking Changes | Low | Audit the full changelog for hidden deprecations. Test with php -d error_reporting=E_ALL in a staging environment. |
| Performance Regression | Low | Benchmark critical paths (e.g., 10K-node path rendering) against v0.16.0 using Blackfire. PHP 8.4’s JIT may improve or degrade performance depending on SVG complexity. |
| CI/CD Pipeline Updates | Medium | Update Laravel’s phpunit.xml to use PHP 8.4’s assertSame behavior (e.g., stricter SVG string comparisons). |
| Third-Party Tooling | Low | Verify compatibility with tools like Laravel Mix (if using SVG sprites) or Spatie’s media library (for SVG uploads). |
| Deprecated PHP Features | High | Scan custom SVG logic for uses of create_function, call_user_func_array with variadic args, or dynamic properties. Refactor using PHP 8.4’s alternatives (e.g., call_user_func with type hints). |
assert($element->x is float))?Fiber scheduler.assertSame for SVG strings)?enum support could simplify this.// Laravel Facade Example
Svg::rect()
->width(100) // int
->height(50) // int
->fill('#ff0000') // string
->render();
readonly properties to lock SVG attributes post-creation:
class SvgElement {
public function __construct(
public readonly string $tag,
public readonly array $attributes
) {}
}
app()->bind() can catch PHP 8.4 deprecation warnings:
app()->bind(SvgGenerator::class, function () {
error_reporting(E_ALL & ~E_DEPRECATED); // Suppress warnings (or log them)
return new \Meyfa\Svg\Svg();
});
@svg('icon', [
'width' => 24,
'height' => 24,
'fill' => 'currentColor',
])
match expression to handle SVG content types:
return match ($request->header('Accept')) {
'application/svg+xml' => response($svg->render(), 200, ['Content-Type' => 'image/svg+xml']),
default => response()->json(['error' => 'Unsupported format']),
};
Fiber-compatible jobs (PHP 8.4):
class GenerateComplexSvgJob extends Job {
use Dispatchable, InteractsWithQueues;
public function handle() {
$svg = new \Meyfa\Svg\Svg();
// ... generate SVG ...
Storage::put('svg/complex.svg', $svg->render());
}
}
assertStringContainsString for SVG validation:
$svg = Svg::circle()->radius(50)->render();
$this->assertStringContainsString('<circle r="50"', $svg
How can I help you explore Laravel packages today?