Skip to content

Commit 8ffbdb5

Browse files
Allow notification center to be passed in to Optimizely (#186)
1 parent 043a906 commit 8ffbdb5

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/Optimizely/Optimizely.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class Optimizely
111111
* @param $errorHandler ErrorHandlerInterface
112112
* @param $skipJsonValidation boolean representing whether JSON schema validation needs to be performed.
113113
* @param $userProfileService UserProfileServiceInterface
114+
* @param $configManager ProjectConfigManagerInterface provides ProjectConfig through getConfig method.
115+
* @param $notificationCenter NotificationCenter
114116
*/
115117
public function __construct(
116118
$datafile,
@@ -119,20 +121,17 @@ public function __construct(
119121
ErrorHandlerInterface $errorHandler = null,
120122
$skipJsonValidation = false,
121123
UserProfileServiceInterface $userProfileService = null,
122-
ProjectConfigManagerInterface $configManager = null
124+
ProjectConfigManagerInterface $configManager = null,
125+
NotificationCenter $notificationCenter = null
123126
) {
124127
$this->_isValid = true;
125128
$this->_eventDispatcher = $eventDispatcher ?: new DefaultEventDispatcher();
126129
$this->_logger = $logger ?: new NoOpLogger();
127130
$this->_errorHandler = $errorHandler ?: new NoOpErrorHandler();
128131
$this->_eventBuilder = new EventBuilder($this->_logger);
129132
$this->_decisionService = new DecisionService($this->_logger, $userProfileService);
130-
$this->notificationCenter = new NotificationCenter($this->_logger, $this->_errorHandler);
131-
$this->_projectConfigManager = $configManager;
132-
133-
if ($this->_projectConfigManager === null) {
134-
$this->_projectConfigManager = new StaticProjectConfigManager($datafile, $skipJsonValidation, $this->_logger, $this->_errorHandler);
135-
}
133+
$this->notificationCenter = $notificationCenter ?: new NotificationCenter($this->_logger, $this->_errorHandler);
134+
$this->_projectConfigManager = $configManager ?: new StaticProjectConfigManager($datafile, $skipJsonValidation, $this->_logger, $this->_errorHandler);
136135
}
137136

138137
/**
@@ -148,7 +147,7 @@ protected function getConfig()
148147
/**
149148
* Helper function to validate user inputs into the API methods.
150149
*
151-
* @param $userId string ID for user.
150+
* @param $attributes array Associative array of user attributes
152151
* @param $eventTags array Hash representing metadata associated with an event.
153152
*
154153
* @return boolean Representing whether all user inputs are valid.

src/Optimizely/ProjectConfigManager/HTTPProjectConfigManager.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
use Monolog\Logger;
2323
use Optimizely\Config\DatafileProjectConfig;
2424
use Optimizely\Enums\ProjectConfigManagerConstants;
25+
use Optimizely\ErrorHandler\ErrorHandlerInterface;
2526
use Optimizely\ErrorHandler\NoOpErrorHandler;
27+
use Optimizely\Logger\LoggerInterface;
2628
use Optimizely\Logger\NoOpLogger;
2729
use Optimizely\Notification\NotificationCenter;
2830
use Optimizely\Notification\NotificationType;
@@ -77,17 +79,14 @@ public function __construct(
7779
$fetchOnInit = true,
7880
$datafile = null,
7981
$skipJsonValidation = false,
80-
$logger = null,
81-
$errorHandler = null,
82-
$notificationCenter = null
82+
LoggerInterface $logger = null,
83+
ErrorHandlerInterface $errorHandler = null,
84+
NotificationCenter $notificationCenter = null
8385
) {
8486
$this->_skipJsonValidation = $skipJsonValidation;
8587
$this->_logger = $logger ?: new NoOpLogger();
8688
$this->_errorHandler = $errorHandler ?: new NoOpErrorHandler();
87-
$this->_notificationCenter = $notificationCenter;
88-
if (!($this->_notificationCenter instanceof NotificationCenter)) {
89-
$this->_notificationCenter = new NotificationCenter($this->_logger, $this->_errorHandler);
90-
}
89+
$this->_notificationCenter = $notificationCenter ?: new NotificationCenter($this->_logger, $this->_errorHandler);
9190
$this->httpClient = new HttpClient();
9291
$this->_url = $this->getUrl($sdkKey, $url, $urlTemplate);
9392

0 commit comments

Comments
 (0)