@@ -126,9 +126,6 @@ |
||
126 | 126 | * Builds up a multipart form-like array for Guzzle |
127 | 127 | * |
128 | 128 | * @param array $data The original object in array form |
129 | - * @param string $fileKeyName A file handler will be sent instead of a string, state here which field it is |
|
130 | - * @param resource $stream The actual file handler |
|
131 | - * @param string $filename |
|
132 | 129 | * @return array Returns the actual formdata to be sent |
133 | 130 | */ |
134 | 131 | public function constructMultipartOptions(array $data, array $multipart_data): array |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace unreal4u\TelegramAPI\InternalFunctionality; |
6 | 6 | |
@@ -83,31 +83,31 @@ discard block |
||
83 | 83 | $return = []; |
84 | 84 | |
85 | 85 | foreach ($method as $key => $value) { |
86 | - if ((\is_object($value) && $value instanceof InputFile)||(\is_object($value) && $value instanceof Photo)||((is_array($value) || $value instanceof Countable) && \count($value)>1 && (reset($value) instanceof InputFile||reset($value) instanceof Photo))) { |
|
86 | + if ((\is_object($value) && $value instanceof InputFile) || (\is_object($value) && $value instanceof Photo) || ((is_array($value) || $value instanceof Countable) && \count($value) > 1 && (reset($value) instanceof InputFile || reset($value) instanceof Photo))) { |
|
87 | 87 | $this->logger->debug('About to send a file, so changing request to use multi-part instead'); |
88 | 88 | // If we are about to send a file, we must use the multipart/form-data way |
89 | 89 | $this->formType = 'multipart/form-data'; |
90 | - if($value instanceof InputFile){ |
|
90 | + if ($value instanceof InputFile) { |
|
91 | 91 | $return[$key] = [ |
92 | 92 | 'id' => $key, |
93 | 93 | 'filename' => $value->path, |
94 | 94 | 'stream' => $value->getStream() |
95 | 95 | ]; |
96 | - }elseif($value instanceof Photo){ |
|
96 | + }elseif ($value instanceof Photo) { |
|
97 | 97 | $return[$key] = [ |
98 | 98 | 'id' => $key, |
99 | 99 | 'filename' => $value->media->path, |
100 | 100 | 'stream' => $value->media->getStream() |
101 | 101 | ]; |
102 | - }elseif((is_array($value) || $value instanceof Countable)){ |
|
103 | - foreach ($value as $kk => $vv){ |
|
104 | - if($vv instanceof InputFile){ |
|
102 | + }elseif ((is_array($value) || $value instanceof Countable)) { |
|
103 | + foreach ($value as $kk => $vv) { |
|
104 | + if ($vv instanceof InputFile) { |
|
105 | 105 | $return[$kk] = [ |
106 | 106 | 'id' => $kk, |
107 | 107 | 'filename' => $vv->path, |
108 | 108 | 'stream' => $vv->getStream() |
109 | 109 | ]; |
110 | - }elseif($vv instanceof Photo){ |
|
110 | + }elseif ($vv instanceof Photo) { |
|
111 | 111 | $return[$kk] = [ |
112 | 112 | 'id' => $kk, |
113 | 113 | 'filename' => $vv->media->path, |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | $builder = new Builder(); |
137 | 137 | $this->logger->debug('Creating multi-part form array data (complex and expensive)'); |
138 | 138 | foreach ($data as $id => $value) { |
139 | - if (array_key_exists($id,$multipart_data)) { |
|
139 | + if (array_key_exists($id, $multipart_data)) { |
|
140 | 140 | $data = new MultipartData( |
141 | - (string) $multipart_data[$id]['id'], |
|
141 | + (string)$multipart_data[$id]['id'], |
|
142 | 142 | stream_get_contents($multipart_data[$id]['stream']), |
143 | 143 | pathinfo($multipart_data[$id]['filename'], PATHINFO_BASENAME) |
144 | 144 | ); |
145 | 145 | $builder->append($data); |
146 | - } elseif($id=='mediagroup') { |
|
147 | - foreach($multipart_data as $ii => $mdata){ |
|
146 | + } elseif ($id == 'mediagroup') { |
|
147 | + foreach ($multipart_data as $ii => $mdata) { |
|
148 | 148 | $data = new MultipartData( |
149 | 149 | pathinfo($mdata['filename'], PATHINFO_BASENAME), |
150 | 150 | stream_get_contents($mdata['stream']), |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $builder->append($data); |
154 | 154 | } |
155 | 155 | } else { |
156 | - $data = new MultipartData((string) $id, (string) $value); |
|
156 | + $data = new MultipartData((string)$id, (string)$value); |
|
157 | 157 | $builder->append($data); |
158 | 158 | } |
159 | 159 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $body = $builder->buildAll(); |
162 | 162 | $array = [ |
163 | 163 | 'headers' => [ |
164 | - 'Content-Type' => 'multipart/form-data; boundary="' . $builder->getBoundary() . '"', |
|
164 | + 'Content-Type' => 'multipart/form-data; boundary="'.$builder->getBoundary().'"', |
|
165 | 165 | 'Content-Length' => \strlen($body) |
166 | 166 | ], |
167 | 167 | 'body' => $body |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | 'filename' => $value->path, |
94 | 94 | 'stream' => $value->getStream() |
95 | 95 | ]; |
96 | - }elseif($value instanceof Photo){ |
|
96 | + } elseif($value instanceof Photo){ |
|
97 | 97 | $return[$key] = [ |
98 | 98 | 'id' => $key, |
99 | 99 | 'filename' => $value->media->path, |
100 | 100 | 'stream' => $value->media->getStream() |
101 | 101 | ]; |
102 | - }elseif((is_array($value) || $value instanceof Countable)){ |
|
102 | + } elseif((is_array($value) || $value instanceof Countable)){ |
|
103 | 103 | foreach ($value as $kk => $vv){ |
104 | 104 | if($vv instanceof InputFile){ |
105 | 105 | $return[$kk] = [ |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | 'filename' => $vv->path, |
108 | 108 | 'stream' => $vv->getStream() |
109 | 109 | ]; |
110 | - }elseif($vv instanceof Photo){ |
|
110 | + } elseif($vv instanceof Photo){ |
|
111 | 111 | $return[$kk] = [ |
112 | 112 | 'id' => $kk, |
113 | 113 | 'filename' => $vv->media->path, |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace unreal4u\TelegramAPI\Telegram\Methods; |
6 | 6 | |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | return parent::performSpecialConditions(); |
79 | 79 | } |
80 | 80 | |
81 | - public function addMediaStream($path,$caption) |
|
81 | + public function addMediaStream($path, $caption) |
|
82 | 82 | { |
83 | - $phfile=new Photo(); |
|
84 | - $phfile->media= 'attach://'. pathinfo($path, PATHINFO_BASENAME); |
|
85 | - $phfile->caption=$caption; |
|
86 | - $this->media[]=$phfile; |
|
87 | - $this->mediagroup[]=new InputFile($path); |
|
83 | + $phfile = new Photo(); |
|
84 | + $phfile->media = 'attach://'.pathinfo($path, PATHINFO_BASENAME); |
|
85 | + $phfile->caption = $caption; |
|
86 | + $this->media[] = $phfile; |
|
87 | + $this->mediagroup[] = new InputFile($path); |
|
88 | 88 | } |
89 | 89 | } |