Installation:
composer require avkluchko/x509-bundle
Ensure ext-openssl is enabled in your PHP environment.
Register Bundle (if not using Symfony Flex):
Add to config/bundles.php:
return [
// ...
AVKluchko\X509Bundle\X509Bundle::class => ['all' => true],
];
First Use Case: Parse a certificate in a controller or service:
use AVKluchko\X509Bundle\Service\Parser;
class CertificateController extends Controller {
public function parseCertificate(Parser $parser) {
$certData = $parser->parse(storage_path('app/cert.pem'));
return response()->json($certData);
}
}
Certificate Parsing:
Parser service to extract details from .pem, .crt, or .der files:
$parser->parse(file_get_contents('certificate.crt'));
Validation:
$parser->validate($certData, new \DateTime());
Integration with Government Bundle:
avkluchko/government-bundle, leverage combined workflows for government-issued certificates (e.g., eIDAS compliance).Dependency Injection:
Parser into services/controllers for reusable logic:
public function __construct(private Parser $parser) {}
public function handle(Request $request, Closure $next) {
$cert = $request->getClientCert();
$parser->validate($cert, now());
return $next($request);
}
foreach (glob(storage_path('certs/*.pem')) as $cert) {
$data = $parser->parse($cert);
// Process $data
}
OpenSSL Dependency:
ext-openssl will cause runtime errors. Verify with:
php -m | grep openssl
File vs. String Input:
parse() accepts both file paths and raw strings, but mixing them may cause issues. Stick to one format per operation.Certificate Format:
Government Bundle Dependency:
avkluchko/government-bundle, ignore its related features (e.g., GovernmentCertificateParser).try-catch to handle exceptions:
try {
$parser->validate($cert, now());
} catch (\AVKluchko\X509Bundle\Exception\InvalidCertificateException $e) {
log::error($e->getMessage());
}
log::debug('Certificate data:', $parser->parse($cert));
Custom Parsers:
Parser to add domain-specific logic:
class CustomParser extends Parser {
public function extractCustomField($certData) {
return $certData['extensions']['custom_field'] ?? null;
}
}
Configuration:
config/packages/avkluchko_x509.yaml:
parser:
default_format: 'PEM' # or 'DER'
Symfony Events:
certificate.parsed). Requires manual event listener setup.How can I help you explore Laravel packages today?