class Raven in Raven: Sentry Integration 8.2
Same name in this branch
- 8.2 src/Logger/Raven.php \Drupal\raven\Logger\Raven
- 8.2 src/Plugin/CspReportingHandler/Raven.php \Drupal\raven\Plugin\CspReportingHandler\Raven
Same name and namespace in other branches
- 3.x src/Plugin/CspReportingHandler/Raven.php \Drupal\raven\Plugin\CspReportingHandler\Raven
CSP Reporting Plugin for a Sentry endpoint.
Plugin annotation
@CspReportingHandler(
id = "raven",
label = "Sentry",
description = @Translation("Reports will be sent to Sentry."),
)
Hierarchy
- class \Drupal\csp\Plugin\ReportingHandlerBase implements ReportingHandlerInterface
- class \Drupal\raven\Plugin\CspReportingHandler\Raven implements ContainerFactoryPluginInterface
Expanded class hierarchy of Raven
File
- src/
Plugin/ CspReportingHandler/ Raven.php, line 20
Namespace
Drupal\raven\Plugin\CspReportingHandlerView source
class Raven extends ReportingHandlerBase implements ContainerFactoryPluginInterface {
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, $configFactory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $configFactory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function alterPolicy(Csp $policy) {
if (!class_exists(\Raven_Client::class)) {
return;
}
$config = $this->configFactory
->get('raven.settings');
try {
$dsn = \Raven_Client::parseDSN(empty($_SERVER['SENTRY_DSN']) ? $config
->get('public_dsn') : $_SERVER['SENTRY_DSN']);
} catch (\InvalidArgumentException $e) {
// Raven is incorrectly configured.
return;
}
$query = [
'sentry_key' => $dsn['public_key'],
];
if ($environment = empty($_SERVER['SENTRY_ENVIRONMENT']) ? $config
->get('environment') : $_SERVER['SENTRY_ENVIRONMENT']) {
$query['sentry_environment'] = $environment;
}
if ($release = empty($_SERVER['SENTRY_RELEASE']) ? $config
->get('release') : $_SERVER['SENTRY_RELEASE']) {
$query['sentry_release'] = $release;
}
$policy
->setDirective('report-uri', Url::fromUri(str_replace('/store/', '/security/', $dsn['server']), [
'query' => $query,
])
->toString());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Raven:: |
protected | property | The configuration factory. | |
Raven:: |
public | function |
Alter the provided policy according to the plugin settings. Overrides ReportingHandlerBase:: |
|
Raven:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
Raven:: |
public | function |
Reporting Handler plugin constructor. Overrides ReportingHandlerBase:: |
|
ReportingHandlerBase:: |
protected | property | The Plugin Configuration. | |
ReportingHandlerBase:: |
protected | property | The Plugin Definition. | |
ReportingHandlerBase:: |
protected | property | The Plugin ID. | |
ReportingHandlerBase:: |
public | function |
Get the form fields for configuring this reporting handler. Overrides ReportingHandlerInterface:: |
2 |
ReportingHandlerBase:: |
public | function |
Validate the form fields of this report handler. Overrides ReportingHandlerInterface:: |
2 |