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) {
      $result = db_query("SELECT * FROM {watchdog} WHERE wid = :wid", array(
        ':wid' => $id,
      ))
        ->fetchObject();
      if (!empty($result)) {

        // Serialization is done here, so we indicate with NULL that there is no
        // subsequent serialization necessary.
        $response = new ResourceResponse(NULL, 200, array(
          'Content-Type' => 'application/json',
        ));

        // @todo remove hard coded format here.
        $response
          ->setContent(drupal_json_encode($result));
        return $response;
      }
    }
    throw new NotFoundHttpException('Not Found');
  }

}

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::$discovery protected property The discovery object.
PluginBase::$plugin_id protected property The plugin_id.
PluginBase::getDefinition public function Implements Drupal\Component\Plugin\PluginInterface::getDefinition(). Overrides PluginInspectionInterface::getDefinition
PluginBase::getPluginId public function Implements Drupal\Component\Plugin\PluginInterface::getPluginId(). Overrides PluginInspectionInterface::getPluginId
PluginBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object. 8
ResourceBase::permissions public function Provides an array of permissions suitable for hook_permission().
ResourceBase::requestMethods protected function Provides predefined HTTP request methods.