DBLogResource.php in Drupal 9
File
core/modules/dblog/src/Plugin/rest/resource/DBLogResource.php
View source
<?php
namespace Drupal\dblog\Plugin\rest\resource;
use Drupal\Core\Database\Database;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class DBLogResource extends ResourceBase {
public function get($id = NULL) {
if ($id) {
$record = Database::getConnection()
->query("SELECT * FROM {watchdog} WHERE [wid] = :wid", [
':wid' => $id,
])
->fetchAssoc();
if (!empty($record)) {
return new ResourceResponse($record);
}
throw new NotFoundHttpException("Log entry with ID '{$id}' was not found");
}
throw new BadRequestHttpException('No log entry ID was provided');
}
}
Classes
Name |
Description |
DBLogResource |
Provides a resource for database watchdog log entries. |