/** * Package constructor * @param UploadSession $uploadSession * @param int $index * @param array $post * @param array $files */ function __construct($uploadSession, $index, $saveIntoCache = false) { if (empty($uploadSession)) { throw new Exception('Upload session can not be null'); } $post = $uploadSession->getRequestFields(); $files = $uploadSession->getRequestFiles(); $this->_uploadSession = $uploadSession; $this->_packageIndex = $index; $uploadSessionId = $uploadSession->getUploadSessionId(); if ($index < $post[PostFields::packageIndex]) { // This is previous package we save for AllPackages event $this->_completed = true; $this->_cached = true; } else { if ($index == $post[PostFields::packageIndex]) { // this package is current package $this->_completed = @(!empty($post[PostFields::packageComplete])); $cache = $this->_uploadSession->getUploadCache(); $this->_cached = $cache->isPackageCached($uploadSessionId, $this->_packageIndex); // If package completed, but already cached then it is last chunk of the package // and we also need to save it. if (!$this->_completed || $this->_cached || $saveIntoCache) { $cache->saveRequestData($uploadSessionId, $this->_packageIndex, $post, $files); $this->_cached = true; } else { $this->_packageFields = $post; $this->_packageFiles = $files; } } else { throw new Exception('Incorrect $index value or POST fields.'); } } }