Download the PHP package gowelle/azure-moderator without Composer
On this page you can find all versions of the php package gowelle/azure-moderator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package azure-moderator
Azure Content Safety for Laravel
A Laravel package for content moderation using Azure Content Safety API. This package helps you analyze both text and image content for potentially harmful material, automatically flagging or approving content based on Azure's AI-powered analysis.
Table of Contents
- Features
- Requirements
- Installation
- Configuration
- Configuration Options
- Usage
- Text Moderation
- Image Moderation
- Laravel Validation
- Error Handling
- Multimodal Analysis (Preview)
- Multi-Modal Analysis (Batch & Async)
- Custom Blocklists
- Protected Material Detection
- Artisan Commands
- Testing
- Running Tests
- Integration Tests
- Quality Tools
- CI/CD
- Documentation
- Changelog
- Contributing
- Security
- Credits
- License
Features
- Easy integration with Azure Content Safety API
- Text and Image content moderation
- Multimodal Analysis (Preview) - Combined text + image analysis
- Multi-Modal Analysis (Batch & Async)
- Custom Blocklist Management
- Protected Material Detection
- Strongly-typed DTO responses (ModerationResult, CategoryAnalysis, MultimodalResult)
- Automatic content analysis and flagging
- Configurable severity thresholds
- User rating support (for text moderation)
- Laravel validation rules for text and images
- Artisan commands for testing & management
- Retry handling for API failures
- Comprehensive test suite (90+ tests)
- Integration tests with real Azure API
- PHPStan level 6 static analysis
- Performance benchmarks
- Laravel-native configuration
- Extensive logging
Requirements
- PHP 8.3 or higher
- Laravel 11.0 or higher
- Azure Content Safety API subscription
Installation
Install the package via composer:
Publish the configuration file:
Configuration
Add your Azure credentials to your .env file:
Configuration Options
AZURE_CONTENT_SAFETY_ENDPOINT: Your Azure Content Safety API endpoint URLAZURE_CONTENT_SAFETY_API_KEY: Your Azure API key (keep this secure!)AZURE_CONTENT_SAFETY_LOW_RATING_THRESHOLD: Minimum rating to approve text content (0-5, default: 2)AZURE_CONTENT_SAFETY_HIGH_SEVERITY_THRESHOLD: Minimum severity to flag content (0-7, default: 3)AZURE_MODERATOR_FAIL_ON_ERROR: Whether validation should fail when API is unavailable (default: false)
Usage
Text Moderation
Basic Usage
Custom Categories
Image Moderation
Basic Image Moderation
Base64 Image Moderation
Note: Base64 images are limited to 4MB of encoded data, which corresponds to approximately 3MB of original image size (due to base64 encoding overhead of ~33%).
Image Moderation with Custom Categories
Laravel Validation
Use the SafeImage validation rule to automatically validate uploaded images:
Error Handling
The package provides flexible error handling to ensure both security and user experience:
Graceful Degradation and Strict Mode
The fail_on_api_error configuration controls how the package behaves when the Azure API is unavailable:
Default Behavior (fail_on_api_error = false):
- When the Azure API fails or is unavailable, both
moderate()andmoderateImage()return approved status - The
SafeImagevalidation rule passes validation, allowing content through - This prevents blocking users during API outages
- Best for: Production environments prioritizing user experience
Strict Mode (fail_on_api_error = true):
- When the Azure API fails, the
SafeImagevalidation rule fails with message: "Unable to validate :attribute safety. Please try again." - Content cannot be moderated until the API is available
- Best for: High-security environments requiring strict content moderation enforcement
Configuration:
Retry Logic: The package includes automatic retry logic with exponential backoff for:
- Rate limit errors (429)
- Server errors (500, 503)
- Up to 3 retry attempts per request
Multimodal Analysis (Preview)
⚠️ Preview API: Uses
2024-09-15-preview. Feature availability varies by Azure region.
Analyze images with associated text for contextual content moderation:
SafeMultimodal Validation Rule
CLI Testing
Multi-Modal Analysis (Batch & Async)
Process multiple items or perform context-aware analysis:
For background processing, dispatch the job:
Custom Blocklists
Manage custom blocklists to filter specific terms.
Use in moderation:
See Blocklists Guide for full details.
Protected Material Detection
Detect copyrighted content in text:
Or use the validation rule:
See Protected Material Guide for details.
Artisan Commands
Test image moderation from the command line:
Testing
This package includes a comprehensive test suite with unit tests, integration tests, and performance benchmarks.
Running Tests
Integration Tests
Integration tests validate the package against the real Azure Content Safety API. To run them:
-
Copy the example environment file:
-
Add your Azure credentials to
.env.integration: - Run integration tests:
Test Coverage:
- 30+ unit tests
- 50+ integration tests (Azure API)
- 10+ performance benchmarks
- Total: 90+ tests with 100% pass rate
See Integration Testing Guide for detailed documentation.
Quality Tools
CI/CD
GitHub Actions automatically runs:
- Unit tests (PHP 8.3, 8.4, and 8.5)
- Integration tests (when secrets are configured)
- PHPStan static analysis
- Code style checks
To enable integration tests in CI, add these secrets to your repository:
AZURE_CONTENT_SAFETY_ENDPOINTAZURE_CONTENT_SAFETY_API_KEY
Documentation
- Blocklists Guide
- Protected Material Guide
- Integration Testing Guide
- Performance Testing Guide
- Troubleshooting Guide
- API Response Examples
- Roadmap
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Please review our Security Policy for more details.
Credits
- John Gowelle
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of azure-moderator with dependencies
illuminate/support Version ^11.0 || ^12.0 || ^13.0
guzzlehttp/guzzle Version ^7.9