From 08725d4efe7b2e3c62badb59ae434e69cd2bfdbd Mon Sep 17 00:00:00 2001 From: aliabbasrizvi Date: Wed, 28 Aug 2019 13:46:48 -0700 Subject: [PATCH] Allow notification center to be passed in to Optimizely --- src/Optimizely/Optimizely.php | 15 +++++++-------- .../HTTPProjectConfigManager.php | 13 ++++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Optimizely/Optimizely.php b/src/Optimizely/Optimizely.php index 6325861b..d6349fb9 100644 --- a/src/Optimizely/Optimizely.php +++ b/src/Optimizely/Optimizely.php @@ -111,6 +111,8 @@ class Optimizely * @param $errorHandler ErrorHandlerInterface * @param $skipJsonValidation boolean representing whether JSON schema validation needs to be performed. * @param $userProfileService UserProfileServiceInterface + * @param $configManager ProjectConfigManagerInterface provides ProjectConfig through getConfig method. + * @param $notificationCenter NotificationCenter */ public function __construct( $datafile, @@ -119,7 +121,8 @@ public function __construct( ErrorHandlerInterface $errorHandler = null, $skipJsonValidation = false, UserProfileServiceInterface $userProfileService = null, - ProjectConfigManagerInterface $configManager = null + ProjectConfigManagerInterface $configManager = null, + NotificationCenter $notificationCenter = null ) { $this->_isValid = true; $this->_eventDispatcher = $eventDispatcher ?: new DefaultEventDispatcher(); @@ -127,12 +130,8 @@ public function __construct( $this->_errorHandler = $errorHandler ?: new NoOpErrorHandler(); $this->_eventBuilder = new EventBuilder($this->_logger); $this->_decisionService = new DecisionService($this->_logger, $userProfileService); - $this->notificationCenter = new NotificationCenter($this->_logger, $this->_errorHandler); - $this->_projectConfigManager = $configManager; - - if ($this->_projectConfigManager === null) { - $this->_projectConfigManager = new StaticProjectConfigManager($datafile, $skipJsonValidation, $this->_logger, $this->_errorHandler); - } + $this->notificationCenter = $notificationCenter ?: new NotificationCenter($this->_logger, $this->_errorHandler); + $this->_projectConfigManager = $configManager ?: new StaticProjectConfigManager($datafile, $skipJsonValidation, $this->_logger, $this->_errorHandler); } /** @@ -148,7 +147,7 @@ protected function getConfig() /** * Helper function to validate user inputs into the API methods. * - * @param $userId string ID for user. + * @param $attributes array Associative array of user attributes * @param $eventTags array Hash representing metadata associated with an event. * * @return boolean Representing whether all user inputs are valid. diff --git a/src/Optimizely/ProjectConfigManager/HTTPProjectConfigManager.php b/src/Optimizely/ProjectConfigManager/HTTPProjectConfigManager.php index cbea08d2..22e64e45 100644 --- a/src/Optimizely/ProjectConfigManager/HTTPProjectConfigManager.php +++ b/src/Optimizely/ProjectConfigManager/HTTPProjectConfigManager.php @@ -22,7 +22,9 @@ use Monolog\Logger; use Optimizely\Config\DatafileProjectConfig; use Optimizely\Enums\ProjectConfigManagerConstants; +use Optimizely\ErrorHandler\ErrorHandlerInterface; use Optimizely\ErrorHandler\NoOpErrorHandler; +use Optimizely\Logger\LoggerInterface; use Optimizely\Logger\NoOpLogger; use Optimizely\Notification\NotificationCenter; use Optimizely\Notification\NotificationType; @@ -77,17 +79,14 @@ public function __construct( $fetchOnInit = true, $datafile = null, $skipJsonValidation = false, - $logger = null, - $errorHandler = null, - $notificationCenter = null + LoggerInterface $logger = null, + ErrorHandlerInterface $errorHandler = null, + NotificationCenter $notificationCenter = null ) { $this->_skipJsonValidation = $skipJsonValidation; $this->_logger = $logger ?: new NoOpLogger(); $this->_errorHandler = $errorHandler ?: new NoOpErrorHandler(); - $this->_notificationCenter = $notificationCenter; - if (!($this->_notificationCenter instanceof NotificationCenter)) { - $this->_notificationCenter = new NotificationCenter($this->_logger, $this->_errorHandler); - } + $this->_notificationCenter = $notificationCenter ?: new NotificationCenter($this->_logger, $this->_errorHandler); $this->httpClient = new HttpClient(); $this->_url = $this->getUrl($sdkKey, $url, $urlTemplate);