Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #48 from shyim/add-some-env
Browse files Browse the repository at this point in the history
Add ELASTICSEARCH_URL, CACHE_URL, SESSION_REDIS_URL
  • Loading branch information
chadwcarlson authored Oct 14, 2022
2 parents 222c243 + ab4e92c commit 47812e1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
34 changes: 9 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,18 @@ search_engine_solr:

## Redis Cache

If a Platform.sh relationship named `rediscache` is defined, it will be taken as a the storage engine for a cache pool.
If a Platform.sh relationship named `rediscache` is defined, it will be taken as a the storage engine for a cache pool.

For typical use you will need to define a file looking like this:

```yaml
#config/packages/cache_pool/cache.redis.yaml
parameters:
cache_dsn: '%env(CACHE_DSN)%'
# config/packages/framework.yaml
framework:
cache:
app: cache.adapter.redis
system: cache.adapter.redis
default_redis_provider: "%env(CACHE_URL)%"
services:
cache.redis:
public: true
class: Symfony\Component\Cache\Adapter\RedisTagAwareAdapter
parent: cache.adapter.redis
```
For more details see [here](https://symfony.com/doc/current/components/cache/adapters/redis_adapter.html)

Expand All @@ -118,25 +116,11 @@ If a Platform.sh relationship named `redissession` is defined, it will be taken

For typical use you will need to add a couple of service definitions which looks like this:
```yaml
# config/services.yaml
services:
# ...
Redis:
class: Redis
calls:
- connect:
- '%env(SESSION_REDIS_HOST)%'
- '%env(int:SESSION_REDIS_PORT)%'
Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler:
arguments:
- '@Redis'
```
Then to configure symfony to use the new redis handler
```yaml
# config/packages/framework.yaml
framework:
session:
handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler
handler_id: '%env(SESSION_REDIS_URL)%'
```


For more details see [here](https://symfony.com/doc/current/session/database.html#store-sessions-in-a-key-value-database-redis)
5 changes: 4 additions & 1 deletion platformsh-flex-env.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ function mapPlatformShElasticSearch(string $relationshipName, Config $config): v

setEnvVar('ELASTICSEARCH_HOST', $credentials['host']);
setEnvVar('ELASTICSEARCH_PORT', (string)$credentials['port']);
setEnvVar('ELASTICSEARCH_URL', sprintf('http://%s:%s', $credentials['host'], (string) $credentials['port']));
}

/**
Expand All @@ -320,7 +321,7 @@ function mapPlatformShSolr(string $relationshipName, Config $config): void
$credentials = $config->credentials($relationshipName);

setEnvVar('SOLR_DSN', sprintf('http://%s:%d/solr', $credentials['host'], $credentials['port']));

if(isset($credentials['rel'])) {
setEnvVar('SOLR_CORE', $credentials['rel']);
} else {
Expand All @@ -344,6 +345,7 @@ function mapPlatformShRedisSession(string $relationshipName, Config $config): vo

setEnvVar('SESSION_REDIS_HOST', $credentials['host']);
setEnvVar('SESSION_REDIS_PORT', (string)$credentials['port']);
setEnvVar('SESSION_REDIS_URL', sprintf('redis://%s:%s', $credentials['host'], (string) $credentials['port']));
}

/**
Expand All @@ -361,4 +363,5 @@ function mapPlatformShRedisCache(string $relationshipName, Config $config): void
$credentials = $config->credentials($relationshipName);

setEnvVar('CACHE_DSN', sprintf('%s:%d', $credentials['host'], $credentials['port']));
setEnvVar('CACHE_URL', sprintf('redis://%s:%s', $credentials['host'], (string) $credentials['port']));
}
3 changes: 3 additions & 0 deletions tests/FlexBridgeElasticsearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function testNotOnPlatformshDoesNotSetDatabase(): void

$this->assertArrayNotHasKey('ELASTICSEARCH_HOST', $_SERVER);
$this->assertArrayNotHasKey('ELASTICSEARCH_PORT', $_SERVER);
$this->assertArrayNotHasKey('ELASTICSEARCH_URL', $_SERVER);
}

public function testNoElasticsearchRelationship(): void
Expand All @@ -58,6 +59,7 @@ public function testNoElasticsearchRelationship(): void

$this->assertArrayNotHasKey('ELASTICSEARCH_HOST', $_SERVER);
$this->assertArrayNotHasKey('ELASTICSEARCH_PORT', $_SERVER);
$this->assertArrayNotHasKey('ELASTICSEARCH_URL', $_SERVER);
}

public function testElasticsearchRelationshipSet(): void
Expand All @@ -72,5 +74,6 @@ public function testElasticsearchRelationshipSet(): void

$this->assertEquals('elasticsearch.internal', $_SERVER['ELASTICSEARCH_HOST']);
$this->assertEquals(80, $_SERVER['ELASTICSEARCH_PORT']);
$this->assertEquals('http://elasticsearch.internal:80', $_SERVER['ELASTICSEARCH_URL']);
}
}
7 changes: 5 additions & 2 deletions tests/FlexBridgeRedisCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public function setUp(): void
$this->relationships = [
"rediscache" => [
[

"service" => 'rediscache',
"ip" => "203.0.113.0",
"cluster" => "someCluster",
"host" => "rediscache.internal",
"rel" => "rediscache",
"scheme" => "redis",
"port" => 6379

]
]
];
Expand All @@ -40,6 +40,7 @@ public function testNotOnPlatformshDoesNotSetEnvVar(): void
mapPlatformShEnvironment();

$this->assertArrayNotHasKey('CACHE_DSN', $_SERVER);
$this->assertArrayNotHasKey('CACHE_URL', $_SERVER);
}

public function testNoRedisRelationship(): void
Expand All @@ -56,6 +57,7 @@ public function testNoRedisRelationship(): void
mapPlatformShEnvironment();

$this->assertArrayNotHasKey('CACHE_DSN', $_SERVER);
$this->assertArrayNotHasKey('CACHE_URL', $_SERVER);
$this->assertArrayNotHasKey('SESSION_REDIS_HOST', $_SERVER);
$this->assertArrayNotHasKey('SESSION_REDIS_PORT', $_SERVER);
}
Expand All @@ -73,5 +75,6 @@ public function testRelationshipCache(): void
mapPlatformShEnvironment();

$this->assertEquals('rediscache.internal:6379', $_SERVER['CACHE_DSN']);
$this->assertEquals('redis://rediscache.internal:6379', $_SERVER['CACHE_URL']);
}
}
7 changes: 5 additions & 2 deletions tests/FlexBridgeRedisSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public function setUp(): void
$this->relationships = [
"redissession" => [
[

"service" => 'redissession',
"ip" => "203.0.113.0",
"cluster" => "someCluster",
"host" => "redissession.internal",
"rel" => "redissession",
"scheme" => "redis",
"port" => 6379

]
]
];
Expand All @@ -41,6 +41,7 @@ public function testNotOnPlatformshDoesNotSetEnvVar(): void

$this->assertArrayNotHasKey('SESSION_REDIS_HOST', $_SERVER);
$this->assertArrayNotHasKey('SESSION_REDIS_PORT', $_SERVER);
$this->assertArrayNotHasKey('SESSION_REDIS_URL', $_SERVER);
}

public function testNoRedisRelationship(): void
Expand All @@ -58,6 +59,7 @@ public function testNoRedisRelationship(): void

$this->assertArrayNotHasKey('SESSION_REDIS_HOST', $_SERVER);
$this->assertArrayNotHasKey('SESSION_REDIS_PORT', $_SERVER);
$this->assertArrayNotHasKey('SESSION_REDIS_URL', $_SERVER);
}

public function testRelationshipSession(): void
Expand All @@ -74,5 +76,6 @@ public function testRelationshipSession(): void

$this->assertEquals('redissession.internal', $_SERVER['SESSION_REDIS_HOST']);
$this->assertEquals('6379', $_SERVER['SESSION_REDIS_PORT']);
$this->assertEquals('redis://redissession.internal:6379', $_SERVER['SESSION_REDIS_URL']);
}
}

0 comments on commit 47812e1

Please # to comment.