-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement better bulk responses (#2)
* implement better bulk responses * phpunit fix * rename BasicMetaResponse to simple MetaData * remove composer version
- Loading branch information
Showing
20 changed files
with
523 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
|
||
namespace VaultPHP\Response; | ||
|
||
use ArrayAccess; | ||
use Countable; | ||
use Iterator; | ||
use VaultPHP\Exceptions\VaultException; | ||
|
||
/** | ||
* Class BulkEndpointResponse | ||
* @package VaultPHP\Response | ||
*/ | ||
class BulkEndpointResponse extends EndpointResponse implements Iterator, ArrayAccess, Countable | ||
{ | ||
/** @var integer */ | ||
private $iteratorPosition = 0; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $batch_results = []; | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasErrors() { | ||
$errorOccurred = $this->getMetaData()->hasErrors(); | ||
|
||
if (!$errorOccurred) { | ||
/** @var EndpointResponse $batchResult */ | ||
foreach ($this as $batchResult) { | ||
$errorOccurred = $batchResult->getMetaData()->hasErrors(); | ||
if ($errorOccurred) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return $errorOccurred; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getBatchResults() { | ||
return $this->batch_results; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function current() | ||
{ | ||
return $this->batch_results[$this->iteratorPosition]; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function next() | ||
{ | ||
++$this->iteratorPosition; | ||
} | ||
|
||
/** | ||
* @return integer | ||
*/ | ||
public function key() | ||
{ | ||
return (int) $this->iteratorPosition; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function valid() | ||
{ | ||
return isset($this->batch_results[$this->iteratorPosition]); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function rewind() | ||
{ | ||
$this->iteratorPosition = 0; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function count() | ||
{ | ||
return count($this->batch_results); | ||
} | ||
|
||
/** | ||
* @param integer $offset | ||
* @return bool | ||
*/ | ||
public function offsetExists($offset) | ||
{ | ||
return isset($this->batch_results[$offset]); | ||
} | ||
|
||
/** | ||
* @param integer $offset | ||
* @return mixed | ||
*/ | ||
public function offsetGet($offset) | ||
{ | ||
return $this->batch_results[$offset]; | ||
} | ||
|
||
/** | ||
* @param mixed $offset | ||
* @param mixed $value | ||
* @throws VaultException | ||
*/ | ||
public function offsetSet($offset, $value) | ||
{ | ||
throw new VaultException('readonly'); | ||
} | ||
|
||
/** | ||
* @param mixed $offset | ||
* @throws VaultException | ||
*/ | ||
public function offsetUnset($offset) | ||
{ | ||
throw new VaultException('readonly'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.