PHP code example of dwenzel / reporter-api

1. Go to this page and download the library: Download dwenzel/reporter-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dwenzel / reporter-api example snippets




use DWenzel\ReporterApi\Api;
use Psr\Http\Message\ServerRequestInterface;

// Create the API middleware
$reporterApi = new Api();

// Check if the API can handle the request
if ($reporterApi->canHandle($request)) {
    // Process the request and get response
    $response = $reporterApi->process($request, $handler);
}



use DWenzel\ReporterApi\Api;

$api = new Api();
$reportEndpoint = $api->getReportEndpoint();

// Handle a server request
$response = $reportEndpoint->handle($serverRequest);



use DWenzel\ReporterApi\Schema\ApplicationStatus;
use DWenzel\ReporterApi\Schema\Report;

// Create a new report
$report = new Report();

// Set application status using modern PHP enum
$report->setStatus(ApplicationStatus::OK);
$report->setName('My Application');
$report->setApplicationId(12345);

// Get status information
$status = $report->getStatus(); // Returns ApplicationStatus enum
$statusValue = $status->getValue(); // Returns 'ok'



use DWenzel\ReporterApi\Api;

$api = new Api();

// The default endpoint map can be extended
// Default: ['/api/reporter/v1/application/report' => Report::class]

src/
├── Api.php                 # Main middleware class
├── Endpoint/              # HTTP endpoint handlers
│   ├── EndpointInterface.php
│   ├── Report.php         # Main reporting endpoint
│   └── NullEndpoint.php   # Null object for unhandled routes
├── Schema/                # Data models
│   ├── ApplicationStatus.php  # PHP 8.1 enum
│   ├── Report.php
│   ├── Package.php
│   └── ...
├── Http/                  # PSR-7 implementations
│   ├── JsonResponse.php
│   ├── AbstractMessage.php
│   └── ...
└── Traits/                # Reusable functionality
    ├── JsonSerialize.php
    └── ToArray.php