islandora/crayfish-commons
Shared PHP 8+ library for Islandora Crayfish microservices. Provides common Symfony bundle utilities such as ApixMiddleware and command execution services, with simple configuration for Fedora base URI and AP-IX middleware support.
## Getting Started
### **Minimal Setup**
1. **Installation**
Update to the latest version via Composer in your Laravel project:
```bash
composer require islandora/crayfish-commons:^4.1.0
Publish the config (if available) with:
php artisan vendor:publish --provider="Islandora\CrayfishCommons\CrayfishCommonsServiceProvider"
First Use Case: Enhanced Input Escaping Leverage improved escaping utilities for security-sensitive data:
use Islandora\CrayfishCommons\Facades\CrayfishSanitizer;
$safeInput = CrayfishSanitizer::escapeHtml($userInput);
$safeJson = CrayfishSanitizer::escapeJson($apiPayload);
Key Entry Points
CrayfishLogger: Centralized logging facade (unchanged).CrayfishResponse: Standardized API response formatting (unchanged).CrayfishValidator: Shared validation rules (unchanged).CrayfishSanitizer: New utility for robust input escaping (4.1.0+).CrayfishLogger::debug('Processing request', [
'service' => 'user-service',
'request_id' => $request->header('X-Request-ID'),
]);
CrayfishResponse:
return CrayfishResponse::success($data, 'Resource fetched');
$safeTitle = CrayfishSanitizer::escapeHtml($request->input('title'));
$decoded = json_decode(CrayfishSanitizer::escapeJson($request->getContent()), true);
$validator = Validator::make($request->all(), [
'description' => 'required|string|max:255',
]);
$safeDescription = CrayfishSanitizer::escapeHtml($validator->validated('description'));
event(new \Islandora\CrayfishCommons\Events\ServiceEvent('user.created', $userData));
Logger Configuration (Unchanged)
config('logging.default') is set correctly (e.g., 'single').Response Overrides (Unchanged)
CrayfishResponse facade to avoid conflicts.Validation Rules (Unchanged)
AppServiceProvider if not auto-discovered.Escaping Pitfalls (New in 4.1.0)
escapeHtml() multiple times on the same data.
// ❌ Avoid
$doubleEscaped = CrayfishSanitizer::escapeHtml(
CrayfishSanitizer::escapeHtml($input)
);
escapeHtml() for browser output and escapeJson() for API payloads.CrayfishLogger::setLevel('debug') temporarily.X-Trace-ID for cross-service correlation:
CrayfishLogger::setContext(['trace_id' => $request->header('X-Trace-ID')]);
if (strpos($escaped, '&') !== false) {
CrayfishLogger::debug('HTML escaping applied', ['input_sample' => substr($input, 0, 50)]);
}
Custom Log Handlers (Unchanged)
Extend via config/logging.php:
'channels' => [
'crayfish' => [
'driver' => 'single',
'path' => storage_path('logs/crayfish.log'),
'level' => 'debug',
],
],
Sanitizer Decorators (New in 4.1.0) Override escaping behavior globally:
$this->app->singleton(\Islandora\CrayfishCommons\CrayfishSanitizer::class, function () {
return new \App\Services\CustomCrayfishSanitizer();
});
PHP Version Compatibility (4.1.0 Note)
^4.0.0:
composer require islandora/crayfish-commons:^4.0.0
info()/warning() in production.$safeTitles = array_map([CrayfishSanitizer::class, 'escapeHtml'], $titles);
escapeHtml()/escapeJson() as mandatory for:
htmlspecialchars() with CrayfishSanitizer::escapeHtml().
NO_UPDATE_NEEDED would **not** apply here due to the new `CrayfishSanitizer` feature and PHP version updates.
How can I help you explore Laravel packages today?