* @return void
*/
function handleAvailableChunksWithFinal ();
+
+ /**
+ * Checks whether unassembled chunks are available (ready) in final array
+ *
+ * @return $unassembledChunksAvailable Whether unassembled chunks are available
+ */
+ function ifUnassembledChunksAvailable ();
+
+ /**
+ * Assembles all chunks (except EOP and "hash chunk") back together to the original package data.
+ *
+ * This is done by the following steps:
+ *
+ * 1) Sort the final array with ksort(). This will bring the "hash
+ * chunk" up to the last array index and the EOP chunk to the
+ * pre-last array index
+ * 2) Assemble all chunks except two last (see above step)
+ * 3) While so, do the final check on all hashes
+ * 4) If the package is assembled back together, hash it again for
+ * the very final verification.
+ */
+ function assembleChunksFromFinalArray ();
}
// [EOF]
*/
private $finalPackageChunks = array(
// Array for package content
- 'content' => array(),
+ 'content' => array(),
// ... and for the hashes
- 'hashes' => array()
+ 'hashes' => array(),
+ // ... marker for that the final array is complete for assembling all chunks
+ 'is_complete' => false
);
/**
$this->finalPackageChunks['hashes'][$chunkSplits[1]] = $chunkSplits[0];
}
+ /**
+ * Marks the final array as completed, do only this if you really have all
+ * chunks together including EOP and "hash chunk".
+ *
+ * @return void
+ */
+ private function markFinalArrayAsCompleted () {
+ /*
+ * As for now, just set the array element. If any further steps are
+ * being added, this should always be the last step.
+ */
+ $this->finalPackageChunks['is_complete'] = true;
+ }
+
/**
* Adds all chunks if the last one verifies as a 'final chunk'.
*
* Now the chunk can be added to the final array
*/
$this->addChunkToFinalArray($chunkSplits);
+
+ // Is the stack now empty?
+ if ($this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP)) {
+ // Then mark the final array as complete
+ $this->markFinalArrayAsCompleted();
+ } // END - if
+ }
+
+ /**
+ * Checks whether unassembled chunks are available (ready) in final array
+ *
+ * @return $unassembledChunksAvailable Whether unassembled chunks are available
+ */
+ public function ifUnassembledChunksAvailable () {
+ // For now do only check the array element 'is_complete'
+ $unassembledChunksAvailable = ($this->finalPackageChunks['is_complete'] === true);
+
+ // Return status
+ return $unassembledChunksAvailable;
+ }
+
+ /**
+ * Assembles all chunks (except EOP and "hash chunk") back together to the original package data.
+ *
+ * This is done by the following steps:
+ *
+ * 1) Sort the final array with ksort(). This will bring the "hash
+ * chunk" up to the last array index and the EOP chunk to the
+ * pre-last array index
+ * 2) Assemble all chunks except two last (see above step)
+ * 3) While so, do the final check on all hashes
+ * 4) If the package is assembled back together, hash it again for
+ * the very final verification.
+ */
+ public function assembleChunksFromFinalArray () {
+ $this->partialStub('Please implement this method.');
}
}
* @return void
*/
public function executeTask () {
- // Are there chunks to handle?
- if ($this->getHandlerInstance()->ifUnhandledChunksWithFinalAvailable()) {
- // Then handle them (not all!)
+ // Are there chunks to handle or a final array to assemble?
+ if ($this->getHandlerInstance()->ifUnassembledChunksAvailable()) {
+ /*
+ * Then do the final steps:
+ *
+ * 1) Sort the final array with ksort(). This will bring the "hash
+ * chunk" up to the last array index and the EOP chunk to the
+ * pre-last array index
+ * 2) Assemble all chunks except two last (see above step)
+ * 3) While so, do the final check on all hashes
+ * 4) If the package is assembled back together, hash it again for
+ * the very final verification.
+ */
+ $this->getHandlerInstance()->assembleChunksFromFinalArray();
+ } elseif ($this->getHandlerInstance()->ifUnhandledChunksWithFinalAvailable()) {
+ /*
+ * Then handle them (not all!). This should push all chunks into a
+ * 'final array' for last verification.
+ */
$this->getHandlerInstance()->handleAvailableChunksWithFinal();
- } // END - if
+ }
}
}