Some adjustments to make App properly initializable in phpstan context
This commit is contained in:
parent
508dda6562
commit
b100359b63
7 changed files with 27 additions and 3 deletions
|
@ -22,6 +22,9 @@ class Cas extends Method {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
// In phpstan context, do not initialize
|
||||||
|
if (defined('__PHPSTAN_RUNNING__') && constant('__PHPSTAN_RUNNING__'))
|
||||||
|
return true;
|
||||||
self :: $fake_authenticated_user = App :: get(
|
self :: $fake_authenticated_user = App :: get(
|
||||||
'auth.cas.fake_authenticated_user', null, 'string');
|
'auth.cas.fake_authenticated_user', null, 'string');
|
||||||
if (self :: $fake_authenticated_user) return true;
|
if (self :: $fake_authenticated_user) return true;
|
||||||
|
|
|
@ -86,8 +86,13 @@ class Log {
|
||||||
// PHP error_log() fallback
|
// PHP error_log() fallback
|
||||||
self :: $error_log_fallback = App::get('log.error_log_fallback', true, 'bool');
|
self :: $error_log_fallback = App::get('log.error_log_fallback', true, 'bool');
|
||||||
|
|
||||||
// Set log level
|
// Set log level:
|
||||||
self :: set_level($level?$level:App::get('log.level'));
|
// Note: in Phpstan context, force FATAL level
|
||||||
|
if (defined('__PHPSTAN_RUNNING__') && constant('__PHPSTAN_RUNNING__'))
|
||||||
|
self :: set_level('FATAL');
|
||||||
|
else
|
||||||
|
self :: set_level($level?$level:App::get('log.level'));
|
||||||
|
|
||||||
|
|
||||||
// Log PHP errors
|
// Log PHP errors
|
||||||
if (!is_null($php_errors_levels)) {
|
if (!is_null($php_errors_levels)) {
|
||||||
|
|
|
@ -37,6 +37,9 @@ class SentryIntegration {
|
||||||
*/
|
*/
|
||||||
public static function init($dsn=null, $traces_sample_rate=null,
|
public static function init($dsn=null, $traces_sample_rate=null,
|
||||||
$php_error_types=null) {
|
$php_error_types=null) {
|
||||||
|
// In phpstan context, do not initialize
|
||||||
|
if (defined('__PHPSTAN_RUNNING__') && constant('__PHPSTAN_RUNNING__'))
|
||||||
|
return;
|
||||||
\Sentry\init([
|
\Sentry\init([
|
||||||
'dsn' => $dsn?$dsn:App::get('sentry.dsn'),
|
'dsn' => $dsn?$dsn:App::get('sentry.dsn'),
|
||||||
'traces_sample_rate' => (
|
'traces_sample_rate' => (
|
||||||
|
|
|
@ -47,6 +47,9 @@ class SentrySpan {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($op, $name) {
|
public function __construct($op, $name) {
|
||||||
|
// In phpstan context, do not initialize
|
||||||
|
if (defined('__PHPSTAN_RUNNING__') && constant('__PHPSTAN_RUNNING__'))
|
||||||
|
return;
|
||||||
$this -> parent = \Sentry\SentrySdk::getCurrentHub()->getSpan();
|
$this -> parent = \Sentry\SentrySdk::getCurrentHub()->getSpan();
|
||||||
// Check if we have a parent span (this is the case if we started a transaction earlier)
|
// Check if we have a parent span (this is the case if we started a transaction earlier)
|
||||||
if (is_null($this -> parent)) return;
|
if (is_null($this -> parent)) return;
|
||||||
|
|
|
@ -27,6 +27,9 @@ class SentryTransaction {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($op=null, $name=null) {
|
public function __construct($op=null, $name=null) {
|
||||||
|
// In phpstan context, do not initialize
|
||||||
|
if (defined('__PHPSTAN_RUNNING__') && constant('__PHPSTAN_RUNNING__'))
|
||||||
|
return;
|
||||||
// Setup context for the full transaction
|
// Setup context for the full transaction
|
||||||
$this->context = new \Sentry\Tracing\TransactionContext();
|
$this->context = new \Sentry\Tracing\TransactionContext();
|
||||||
$this->context->setName(
|
$this->context->setName(
|
||||||
|
|
|
@ -22,7 +22,11 @@ class Session {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init($max_duration=null, $timeout=null) {
|
public static function init($max_duration=null, $timeout=null) {
|
||||||
if (php_sapi_name() == "cli")
|
// In CLI or Phpstan context, do not initialize
|
||||||
|
if (
|
||||||
|
php_sapi_name() == "cli"
|
||||||
|
|| (defined('__PHPSTAN_RUNNING__') && constant('__PHPSTAN_RUNNING__'))
|
||||||
|
)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Define session max duration
|
// Define session max duration
|
||||||
|
|
|
@ -97,6 +97,9 @@ class Tpl {
|
||||||
*/
|
*/
|
||||||
public static function init($templates_dir=null, $templates_c_dir=null, $debug_ajax=null,
|
public static function init($templates_dir=null, $templates_c_dir=null, $debug_ajax=null,
|
||||||
$static_root_url=null) {
|
$static_root_url=null) {
|
||||||
|
// In phpstan context, do not initialize
|
||||||
|
if (defined('__PHPSTAN_RUNNING__') && constant('__PHPSTAN_RUNNING__'))
|
||||||
|
return;
|
||||||
// Handle templates directories
|
// Handle templates directories
|
||||||
self :: $core_templates_directory = realpath(__DIR__."/../templates");
|
self :: $core_templates_directory = realpath(__DIR__."/../templates");
|
||||||
self :: register_templates_directory(self :: $core_templates_directory);
|
self :: register_templates_directory(self :: $core_templates_directory);
|
||||||
|
|
Loading…
Reference in a new issue