Skip to content

Commit

Permalink
FIX fatal error on delete call; ADD php doc
Browse files Browse the repository at this point in the history
  • Loading branch information
r-simlinger committed Nov 29, 2016
1 parent 4f6f80f commit 585909b
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/SecucardConnect/Client/AbstractError.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace SecucardConnect\Client;


/**
* Class AbstractError
* @package SecucardConnect\Client
*/
abstract class AbstractError extends \Exception
{

Expand Down
11 changes: 10 additions & 1 deletion src/SecucardConnect/Client/ApiError.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ public function getServerError()
return $this->serverError;
}


/**
* ApiError constructor.
*
* @param string $serverError
* @param int $code
* @param Exception $details
* @param $userMessage
* @param $supportId
* @param Exception|null $previous
*/
public function __construct(
$serverError,
$code,
Expand Down
6 changes: 6 additions & 0 deletions src/SecucardConnect/Client/ClientError.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
*/
class ClientError extends AbstractError
{
/**
* ClientError constructor.
*
* @param string $message
* @param Exception|null $previous
*/
public function __construct($message = "", Exception $previous = null)
{
$msg = $message;
Expand Down
13 changes: 10 additions & 3 deletions src/SecucardConnect/Client/DummyStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

namespace SecucardConnect\Client;

/**
* Class DummyStorage
* @package SecucardConnect\Client
*/
class DummyStorage implements StorageInterface {

protected $storage;


/**
* DummyStorage constructor.
*/
public function __construct() {
// init dummy storage var
$this->storage = array();
$this->storage = [];
}

/**
Expand Down Expand Up @@ -51,6 +58,6 @@ public function delete($key) {
* @return void
*/
public function deleteAll() {
$this->storage = array();
$this->storage = [];
}
}
35 changes: 33 additions & 2 deletions src/SecucardConnect/Client/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@

use Psr\Http\Message\StreamInterface;

/**
* Class FileStorage
* @package SecucardConnect\Client
*/
class FileStorage extends DummyStorage
{
private $dir;

/**
* FileStorage constructor.
*
* @param $dir
*
* @throws ClientError
*/
public function __construct($dir)
{
parent::__construct();
Expand Down Expand Up @@ -104,10 +115,13 @@ public function deleteAll()
} catch (\Exception $e) {
return false;
}
$this->storage = array();
$this->storage = [];
return true;
}

/**
* @return bool
*/
private function load()
{
$filename = $this->filePath();
Expand All @@ -119,13 +133,20 @@ private function load()
return false;
}

/**
* @return bool
*/
private function save()
{
file_put_contents($this->filePath(), json_encode($this->storage));
return true;
}


/**
* @param $key
*
* @return bool|int
*/
private function findFile($key)
{
$files = glob($this->filePath($key));
Expand All @@ -146,6 +167,11 @@ private function findFile($key)
return false;
}

/**
* @param $key
*
* @return bool
*/
private function deleteFile($key)
{
$file = $this->findFile($key);
Expand All @@ -160,6 +186,11 @@ private function deleteFile($key)
return unlink($file);
}

/**
* @param $key
*
* @return bool
*/
private function deleteStore($key)
{
if (isset($this->storage[$key])) {
Expand Down
7 changes: 7 additions & 0 deletions src/SecucardConnect/Client/MediaResourceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ public function getContents($cache = true)
return $result;
}

/**
* @param bool $cache
*
* @return null|\Psr\Http\Message\StreamInterface
* @throws ClientError
* @throws \Exception
*/
private function downloadMe($cache = true)
{
if (empty($this->httpClient)) {
Expand Down
Loading

0 comments on commit 585909b

Please sign in to comment.