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
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"extensions": [
"bmewburn.vscode-intelephense-client",
"xdebug.php-debug",
"DEVSENSE.composer-php-vscode"
"DEVSENSE.composer-php-vscode",
"xdebug.php-pack",
"recca0120.vscode-phpunit",
"eamodio.gitlens"
]
}
}
Expand Down
25 changes: 15 additions & 10 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v3
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -25,28 +26,24 @@ jobs:
name: Source Clear Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v3
- name: Source clear scan
env:
SRCCLR_API_TOKEN: ${{ secrets.SRCCLR_API_TOKEN }}
run: curl -sSL https://download.sourceclear.com/ci.sh | bash -s – scan

integration_tests:
name: Integration Tests
uses: optimizely/php-sdk/.github/workflows/integration_test.yml@master
secrets:
CI_USER_TOKEN: ${{ secrets.CI_USER_TOKEN }}
TRAVIS_COM_TOKEN: ${{ secrets.TRAVIS_COM_TOKEN }}

unit_tests:
name: Unit Tests ${{ matrix.php-versions }}
needs: [ linting, source_clear ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: [ '8.1', '8.2' ]
steps:
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v3
- name: Set up PHP v${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
with:
Expand Down Expand Up @@ -77,3 +74,11 @@ jobs:
run: |
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=./build/logs/clover.xml -v

integration_tests:
name: Integration Tests
needs: [ unit_tests ]
uses: optimizely/php-sdk/.github/workflows/integration_test.yml@master
secrets:
CI_USER_TOKEN: ${{ secrets.CI_USER_TOKEN }}
TRAVIS_COM_TOKEN: ${{ secrets.TRAVIS_COM_TOKEN }}
21 changes: 13 additions & 8 deletions src/Optimizely/ProjectConfigManager/HTTPProjectConfigManager.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* Copyright 2019-2020, 2022 Optimizely Inc and Contributors
* Copyright 2019-2020, 2022-2023 Optimizely Inc and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -75,7 +75,12 @@ class HTTPProjectConfigManager implements ProjectConfigManagerInterface
/**
* @var String datafile access token.
*/
private $datafileAccessToken;
private $_datafileAccessToken;

/**
* @var boolean Flag indicates that the datafile access token is valid.
*/
private $_isDatafileAccessTokenValid;

public function __construct(
$sdkKey = null,
Expand All @@ -93,8 +98,8 @@ public function __construct(
$this->_logger = $logger ?: new NoOpLogger();
$this->_errorHandler = $errorHandler ?: new NoOpErrorHandler();
$this->_notificationCenter = $notificationCenter ?: new NotificationCenter($this->_logger, $this->_errorHandler);
$this->datafileAccessToken = $datafileAccessToken;
$this->isDatafileAccessTokenValid = Validator::validateNonEmptyString($this->datafileAccessToken);
$this->_datafileAccessToken = $datafileAccessToken;
$this->_isDatafileAccessTokenValid = Validator::validateNonEmptyString($this->_datafileAccessToken);

$this->httpClient = new HttpClient();
$this->_url = $this->getUrl($sdkKey, $url, $urlTemplate);
Expand Down Expand Up @@ -136,7 +141,7 @@ protected function getUrl($sdkKey, $url, $urlTemplate)
}

if (!Validator::validateNonEmptyString($urlTemplate)) {
if ($this->isDatafileAccessTokenValid) {
if ($this->_isDatafileAccessTokenValid) {
$urlTemplate = ProjectConfigManagerConstants::AUTHENTICATED_DATAFILE_URL_TEMPLATE;
} else {
$urlTemplate = ProjectConfigManagerConstants::DEFAULT_DATAFILE_URL_TEMPLATE;
Expand Down Expand Up @@ -179,8 +184,8 @@ protected function fetchDatafile()
}

// Add Authorization header if access token available.
if ($this->isDatafileAccessTokenValid) {
$headers['Authorization'] = "Bearer {$this->datafileAccessToken}";
if ($this->_isDatafileAccessTokenValid) {
$headers['Authorization'] = "Bearer {$this->_datafileAccessToken}";
}

$options = [
Expand Down