FacebookTransferChunk.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Copyright 2017 Facebook, Inc.
  4. *
  5. * You are hereby granted a non-exclusive, worldwide, royalty-free license to
  6. * use, copy, modify, and distribute this software in source code or binary
  7. * form for use in connection with the web services and APIs provided by
  8. * Facebook.
  9. *
  10. * As with any software that integrates with the Facebook platform, your use
  11. * of this software is subject to the Facebook Developer Principles and
  12. * Policies [http://developers.facebook.com/policy/]. This copyright notice
  13. * shall be included in all copies or substantial portions of the software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. */
  24. namespace Facebook\FileUpload;
  25. /**
  26. * Class FacebookTransferChunk
  27. *
  28. * @package Facebook
  29. */
  30. class FacebookTransferChunk
  31. {
  32. /**
  33. * @var FacebookFile The file to chunk during upload.
  34. */
  35. private $file;
  36. /**
  37. * @var int The ID of the upload session.
  38. */
  39. private $uploadSessionId;
  40. /**
  41. * @var int Start byte position of the next file chunk.
  42. */
  43. private $startOffset;
  44. /**
  45. * @var int End byte position of the next file chunk.
  46. */
  47. private $endOffset;
  48. /**
  49. * @var int The ID of the video.
  50. */
  51. private $videoId;
  52. /**
  53. * @param FacebookFile $file
  54. * @param int $uploadSessionId
  55. * @param int $videoId
  56. * @param int $startOffset
  57. * @param int $endOffset
  58. */
  59. public function __construct(FacebookFile $file, $uploadSessionId, $videoId, $startOffset, $endOffset)
  60. {
  61. $this->file = $file;
  62. $this->uploadSessionId = $uploadSessionId;
  63. $this->videoId = $videoId;
  64. $this->startOffset = $startOffset;
  65. $this->endOffset = $endOffset;
  66. }
  67. /**
  68. * Return the file entity.
  69. *
  70. * @return FacebookFile
  71. */
  72. public function getFile()
  73. {
  74. return $this->file;
  75. }
  76. /**
  77. * Return a FacebookFile entity with partial content.
  78. *
  79. * @return FacebookFile
  80. */
  81. public function getPartialFile()
  82. {
  83. $maxLength = $this->endOffset - $this->startOffset;
  84. return new FacebookFile($this->file->getFilePath(), $maxLength, $this->startOffset);
  85. }
  86. /**
  87. * Return upload session Id
  88. *
  89. * @return int
  90. */
  91. public function getUploadSessionId()
  92. {
  93. return $this->uploadSessionId;
  94. }
  95. /**
  96. * Check whether is the last chunk
  97. *
  98. * @return bool
  99. */
  100. public function isLastChunk()
  101. {
  102. return $this->startOffset === $this->endOffset;
  103. }
  104. /**
  105. * @return int
  106. */
  107. public function getStartOffset()
  108. {
  109. return $this->startOffset;
  110. }
  111. /**
  112. * Get uploaded video Id
  113. *
  114. * @return int
  115. */
  116. public function getVideoId()
  117. {
  118. return $this->videoId;
  119. }
  120. }