@@ -34,6 +34,11 @@ class RollbarHandler extends AbstractProcessingHandler
3434 */
3535 protected $ exclude ;
3636
37+ /**
38+ * @var array
39+ */
40+ protected $ rbConfig ;
41+
3742 /**
3843 * Monolog vs Rollbar
3944 * @var array
@@ -61,10 +66,25 @@ public function __construct(ContainerInterface $container, $level = Logger::ERRO
6166 $ this ->container = $ container ;
6267 parent ::__construct ($ level , $ bubble );
6368
64- // init notifier
65- $ config = $ this ->getContainer ()->getParameter (SymfonyRollbarExtension::ALIAS . '.config ' );
66- $ kernel = $ container ->get ('kernel ' );
69+ $ this ->rbConfig = $ this ->initialize ();
6770
71+ if (!empty ($ this ->rbConfig )) {
72+ RollbarNotifier::init ($ this ->rbConfig , false , false , false );
73+ }
74+ }
75+
76+ /**
77+ * @return array
78+ */
79+ protected function initialize ()
80+ {
81+ try {
82+ $ config = $ this ->getContainer ()->getParameter (SymfonyRollbarExtension::ALIAS . '.config ' );
83+ } catch (\Exception $ e ) {
84+ return null ;
85+ }
86+
87+ $ kernel = $ this ->container ->get ('kernel ' );
6888 $ rConfig = $ config ['rollbar ' ];
6989 $ override = [
7090 'root ' => $ kernel ->getRootDir (),
@@ -75,9 +95,24 @@ public function __construct(ContainerInterface $container, $level = Logger::ERRO
7595 $ rConfig [$ key ] = $ value ;
7696 }
7797
98+ // DI for 'person_fn'
99+ if (!empty ($ rConfig ['person_fn ' ])) {
100+ if ($ this ->container ->has ($ rConfig ['person_fn ' ])) {
101+ $ service = $ this ->container ->get ($ rConfig ['person_fn ' ]);
102+ } elseif (class_exists ($ rConfig ['person_fn ' ])) {
103+ $ service = new $ rConfig ['person_fn ' ]($ this ->container );
104+ }
105+
106+ if (!empty ($ service ) && $ service instanceof AbstractPersonProvider) {
107+ $ rConfig ['person_fn ' ] = [$ service , 'getPerson ' ];
108+ } else {
109+ $ rConfig ['person_fn ' ] = is_callable ($ rConfig ['person_fn ' ]) ? $ rConfig ['person_fn ' ] : null ;
110+ }
111+ }
112+
78113 $ this ->exclude = empty ($ config ['exclude ' ]) ? [] : $ config ['exclude ' ];
79114
80- RollbarNotifier:: init ( $ rConfig, false , false , false ) ;
115+ return $ rConfig ;
81116 }
82117
83118 /**
@@ -93,6 +128,10 @@ public function getContainer()
93128 */
94129 protected function write (array $ record )
95130 {
131+ if (empty ($ this ->rbConfig )) {
132+ return ;
133+ }
134+
96135 if (!$ this ->initialized ) {
97136 // __destructor() doesn't get called on Fatal errors
98137 register_shutdown_function ([$ this , 'close ' ]);
@@ -179,9 +218,7 @@ public function close()
179218 public function trackBuild ($ environment , $ revision , $ comment = '' , $ rollbarUser = '' , $ localUser = '' )
180219 {
181220 // There is no API in Rollbar SDK for tracking builds
182- $ config = $ this ->getContainer ()->getParameter (SymfonyRollbarExtension::ALIAS . '.config ' );
183-
184- if (!$ config ['enable ' ]) {
221+ if (empty ($ this ->rbConfig )) {
185222 return null ;
186223 }
187224
@@ -190,7 +227,7 @@ public function trackBuild($environment, $revision, $comment = '', $rollbarUser
190227
191228 // truncate payload according to limits
192229 $ payload = [
193- 'access_token ' => $ config [ ' rollbar ' ] ['access_token ' ],
230+ 'access_token ' => $ this -> rbConfig ['access_token ' ],
194231 'environment ' => Filter::process ($ environment , Filter \Length::class),
195232 'revision ' => Filter::process ($ revision , Filter \Length::class),
196233 // @link https://stackoverflow.com/questions/4420164/how-much-utf-8-text-fits-in-a-mysql-text-field
0 commit comments