Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/Optimizely/Optimizely.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -119,20 +121,17 @@ 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();
$this->_logger = $logger ?: new NoOpLogger();
$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);
}

/**
Expand All @@ -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.
Expand Down
13 changes: 6 additions & 7 deletions src/Optimizely/ProjectConfigManager/HTTPProjectConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down