diff --git a/.travis.yml b/.travis.yml index 630f03d..dfadab7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ sudo: false env: global: - COMPOSER_ROOT_VERSION=1.0.x-dev - - CORE_RELEASE=master matrix: fast_finish: true @@ -19,12 +18,13 @@ matrix: before_script: - composer self-update || true - - "if [ \"$PHPCS_TEST\" = \"1\" ]; then pyrus install pear/PHP_CodeSniffer; fi" + - export PATH=~/.composer/vendor/bin:$PATH - phpenv rehash - phpenv config-rm xdebug.ini - composer validate - composer install --prefer-dist + - if [[ $PHPCS_TEST ]]; then composer global require squizlabs/php_codesniffer:^3 --prefer-dist --no-interaction --no-progress --no-suggest -o; fi script: - - "if [ \"$PHPUNIT_TEST\" = \"1\" ]; then vendor/bin/phpunit; fi" - - "if [ \"$PHPCS_TEST\" = \"1\" ]; then composer run-script lint; fi" \ No newline at end of file + - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi + - if [[ $PHPCS_TEST ]]; then composer run-script lint; fi diff --git a/_config.php b/_config.php index 8ce002a..e891d7b 100644 --- a/_config.php +++ b/_config.php @@ -1,5 +1,8 @@ register(); + +use SilverStripe\DynamoDb\Model\DynamoDbSession; + +$dynamoSession = DynamoDbSession::get(); +if ($dynamoSession) { + $dynamoSession->register(); } diff --git a/code/Model/DynamoDbSession.php b/code/Model/DynamoDbSession.php index 4ed262a..fde4273 100644 --- a/code/Model/DynamoDbSession.php +++ b/code/Model/DynamoDbSession.php @@ -8,6 +8,7 @@ use Doctrine\Common\Cache\ApcuCache; use SilverStripe\Core\Config\Config; use SilverStripe\Control\Session; +use SilverStripe\Core\Environment; class DynamoDbSession { @@ -44,24 +45,24 @@ public function getHandler() public static function get() { // Use DynamoDB for distributed session storage if it's configured - $AWS_DYNAMODB_SESSION_TABLE = getenv('AWS_DYNAMODB_SESSION_TABLE'); - if (!empty($AWS_DYNAMODB_SESSION_TABLE)) { - $AWS_REGION_NAME = getenv('AWS_REGION_NAME'); - $AWS_DYNAMODB_ENDPOINT = getenv('AWS_DYNAMODB_ENDPOINT'); - $AWS_ACCESS_KEY = getenv('AWS_ACCESS_KEY'); - $AWS_SECRET_KEY = getenv('AWS_SECRET_KEY'); + $awsDynamoDBSessionTable = Environment::getEnv('AWS_DYNAMODB_SESSION_TABLE'); + if (!empty($awsDynamoDBSessionTable)) { + $awsRegionName = Environment::getEnv('AWS_REGION_NAME'); + $awsDynamoDBEndpoint = Environment::getEnv('AWS_DYNAMODB_ENDPOINT'); + $awsAccessKey = Environment::getEnv('AWS_ACCESS_KEY'); + $awsSecretKey = Environment::getEnv('AWS_SECRET_KEY'); - $dynamoOptions = array('region' => $AWS_REGION_NAME); + $dynamoOptions = array('region' => $awsRegionName); // This endpoint can be set for locally testing DynamoDB. // see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html - if (!empty($AWS_DYNAMODB_ENDPOINT)) { - $dynamoOptions['endpoint'] = $AWS_DYNAMODB_ENDPOINT; + if (!empty($awsDynamoDBEndpoint)) { + $dynamoOptions['endpoint'] = $awsDynamoDBEndpoint; } - if (!empty($AWS_ACCESS_KEY) && !empty($AWS_SECRET_KEY)) { - $dynamoOptions['credentials']['key'] = $AWS_ACCESS_KEY; - $dynamoOptions['credentials']['secret'] = $AWS_SECRET_KEY; + if (!empty($awsAccessKey) && !empty($awsSecretKey)) { + $dynamoOptions['credentials']['key'] = $awsAccessKey; + $dynamoOptions['credentials']['secret'] = $awsSecretKey; } else { // cache credentials when IAM fetches the credentials from EC2 metadata service // this will use doctrine/cache (included via composer) to do the actual caching into APCu @@ -69,7 +70,7 @@ public static function get() $dynamoOptions['credentials'] = new DoctrineCacheAdapter(new ApcuCache()); } - return new static($dynamoOptions, $AWS_DYNAMODB_SESSION_TABLE); + return new static($dynamoOptions, $awsDynamoDBSessionTable); } return null; @@ -98,9 +99,9 @@ public function __construct($options, $table) */ protected function getSessionLifetime() { - $AWS_DYNAMODB_SESSION_LIFETIME = getenv('AWS_DYNAMODB_SESSION_LIFETIME'); - if (!empty($AWS_DYNAMODB_SESSION_LIFETIME)) { - return $AWS_DYNAMODB_SESSION_LIFETIME; + $awsDynamoDBSessionLifetime = Environment::getEnv('AWS_DYNAMODB_SESSION_LIFETIME'); + if (!empty($awsDynamoDBSessionLifetime)) { + return $awsDynamoDBSessionLifetime; } if (($timeout = (int)Config::inst()->get(Session::class, 'timeout')) > 0) { return $timeout; diff --git a/composer.json b/composer.json index 81087aa..6f5fb64 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "silverstripe/dynamodb", "description": "SilverStripe DynamoDB integration.", - "type": "silverstripe-module", + "type": "silverstripe-vendormodule", "keywords": ["silverstripe", "aws", "dynamodb"], "license": "BSD-3-Clause", "authors": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c806276..1fb5e69 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,7 +3,7 @@ Standard module phpunit configuration. Requires PHPUnit ^5.7 --> - + tests/