Skip to content

Commit

Permalink
Merge pull request #111 from omniphx/InfusionWeb-master
Browse files Browse the repository at this point in the history
Feature added to store SFDC authentication tokens forever (with PHPSpecs added)
  • Loading branch information
omniphx authored Jul 25, 2016
2 parents 5f23a9a + ab1940f commit b773f12
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
14 changes: 14 additions & 0 deletions spec/Omniphx/Forrest/Providers/Laravel/LaravelCacheSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ public function it_should_allow_a_get(FakeCacheStore $cache)
$this->get('test');
}

public function it_should_allow_storing_cache_forever(FakeCacheStore $cache, Config $config)
{
$config->get(Argument::any())->shouldBeCalled()->willReturn(10);
$config->get('forrest.storage.store_forever')->shouldBeCalled()->willReturn(true);
$cache->forever(Argument::any(), Argument::any())->shouldBeCalled();

$this->put('test', 'value');
}

public function it_should_allow_a_put(FakeCacheStore $cache, Config $config)
{
$config->get(Argument::any())->shouldBeCalled()->willReturn(10);
$config->get('forrest.storage.store_forever')->shouldBeCalled()->willReturn(false);
$cache->put(Argument::any(), Argument::any(), Argument::type('integer'))->shouldBeCalled();

$this->put('test', 'value');
Expand All @@ -57,4 +67,8 @@ public function get($str)
public function put($str)
{
}

public function forever($str)
{
}
}
10 changes: 9 additions & 1 deletion src/Omniphx/Forrest/Providers/Laravel/LaravelCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class LaravelCache extends LaravelStorageProvider
{
public $minutes = 20;

protected $store_forever;

public $path;

protected $cache;
Expand All @@ -23,6 +25,8 @@ public function __construct(Config $config, Cache $cache)
if ($minutes = $config->get('forrest.storage.expire_in')) {
$this->minutes = $minutes;
}

$this->store_forever = $config->get('forrest.storage.store_forever');
}

/**
Expand All @@ -35,7 +39,11 @@ public function __construct(Config $config, Cache $cache)
*/
public function put($key, $value)
{
return $this->cache->put($this->path.$key, $value, $this->minutes);
if ($this->store_forever) {
return $this->cache->forever($this->path.$key, $value);
} else {
return $this->cache->put($this->path.$key, $value, $this->minutes);
}
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/Omniphx/Forrest/Providers/Laravel4/LaravelCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class LaravelCache extends LaravelStorageProvider implements StorageInterface
{
public $minutes = 20;

protected $store_forever;

public $path;

protected $cache;
Expand All @@ -24,6 +26,8 @@ public function __construct(Config $config, Cache $cache)
if ($minutes = $config->get('forrest::config.storage.expire_in')) {
$this->minutes = $minutes;
}

$this->store_forever = $config->get('forrest::config.storage.store_forever');
}

/**
Expand All @@ -36,7 +40,11 @@ public function __construct(Config $config, Cache $cache)
*/
public function put($key, $value)
{
return $this->cache->put($this->path.$key, $value, $this->minutes);
if ($this->store_forever) {
return $this->cache->forever($this->path.$key, $value);
} else {
return $this->cache->put($this->path.$key, $value, $this->minutes);
}
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@
* Where do you want to store access tokens fetched from Salesforce
*/
'storage' => [
'type' => 'session', // 'session' or 'cache' are the two options
'path' => 'forrest_', // unique storage path to avoid collisions
'expire_in' => 60, // number of minutes to expire cache/session
'type' => 'session', // 'session' or 'cache' are the two options
'path' => 'forrest_', // unique storage path to avoid collisions
'expire_in' => 60, // number of minutes to expire cache/session
'store_forever' => false, // never expire cache/session
],

/*
Expand Down

0 comments on commit b773f12

Please sign in to comment.