class DBLogResource

Provides a resource for database watchdog log entries.

Plugin annotation


@Plugin(
  id = "dblog",
  label = @Translation("Watchdog database log")
)

Hierarchy

Expanded class hierarchy of DBLogResource

File

drupal/core/modules/rest/lib/Drupal/rest/Plugin/rest/resource/DBLogResource.php, line 25
Definition of Drupal\rest\Plugin\rest\resource\DBLogResource.

Namespace

Drupal\rest\Plugin\rest\resource
View source
class DBLogResource extends ResourceBase {

  /**
   * Overrides \Drupal\rest\Plugin\ResourceBase::routes().
   */
  public function routes() {

    // Only expose routes if the dblog module is enabled.
    if (module_exists('dblog')) {
      return parent::routes();
    }
    return new RouteCollection();
  }

  /**
   * Responds to GET requests.
   *
   * Returns a watchdog log entry for the specified ID.
   *
   * @return \Drupal\rest\ResourceResponse
   *   The response containing the log entry.
   *
   * @throws \Symfony\Component\HttpKernel\Exception\HttpException
   */
  public function get($id = NULL) {
    if ($id) {
      $record = db_query("SELECT * FROM {watchdog} WHERE wid = :wid", array(
        ':wid' => $id,
      ))
        ->fetchAssoc();
      if (!empty($record)) {
        return new ResourceResponse($record);
      }
    }
    throw new NotFoundHttpException(t('Log entry with ID @id was not found', array(
      '@id' => $id,
    )));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DBLogResource::get public function Responds to GET requests.
DBLogResource::routes public function Overrides \Drupal\rest\Plugin\ResourceBase::routes(). Overrides ResourceBase::routes
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object. 17
ResourceBase::availableMethods public function Implements ResourceInterface::availableMethods(). Overrides ResourceInterface::availableMethods
ResourceBase::permissions public function Implements ResourceInterface::permissions(). Overrides ResourceInterface::permissions
ResourceBase::requestMethods protected function Provides predefined HTTP request methods.