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 */
24namespace Facebook\FileUpload;
25
26/**
27 * Class FacebookTransferChunk
28 *
29 * @package Facebook
30 */
31class FacebookTransferChunk
32{
33    /**
34     * @var FacebookFile The file to chunk during upload.
35     */
36    private $file;
37
38    /**
39     * @var int The ID of the upload session.
40     */
41    private $uploadSessionId;
42
43    /**
44     * @var int Start byte position of the next file chunk.
45     */
46    private $startOffset;
47
48    /**
49     * @var int End byte position of the next file chunk.
50     */
51    private $endOffset;
52
53    /**
54     * @var int The ID of the video.
55     */
56    private $videoId;
57
58    /**
59     * @param FacebookFile $file
60     * @param int $uploadSessionId
61     * @param int $videoId
62     * @param int $startOffset
63     * @param int $endOffset
64     */
65    public function __construct(FacebookFile $file, $uploadSessionId, $videoId, $startOffset, $endOffset)
66    {
67        $this->file = $file;
68        $this->uploadSessionId = $uploadSessionId;
69        $this->videoId = $videoId;
70        $this->startOffset = $startOffset;
71        $this->endOffset = $endOffset;
72    }
73
74    /**
75     * Return the file entity.
76     *
77     * @return FacebookFile
78     */
79    public function getFile()
80    {
81        return $this->file;
82    }
83
84    /**
85     * Return a FacebookFile entity with partial content.
86     *
87     * @return FacebookFile
88     */
89    public function getPartialFile()
90    {
91        $maxLength = $this->endOffset - $this->startOffset;
92
93        return new FacebookFile($this->file->getFilePath(), $maxLength, $this->startOffset);
94    }
95
96    /**
97     * Return upload session Id
98     *
99     * @return int
100     */
101    public function getUploadSessionId()
102    {
103        return $this->uploadSessionId;
104    }
105
106    /**
107     * Check whether is the last chunk
108     *
109     * @return bool
110     */
111    public function isLastChunk()
112    {
113        return $this->startOffset === $this->endOffset;
114    }
115
116    /**
117     * @return int
118     */
119    public function getStartOffset()
120    {
121        return $this->startOffset;
122    }
123
124    /**
125     * Get uploaded video Id
126     *
127     * @return int
128     */
129    public function getVideoId()
130    {
131        return $this->videoId;
132    }
133}
134