Files
Chamilo/vendor/php-xapi/client/src/Http/MultipartStatementBody.php
T
Xes 73154ae174
Behat tests 1.11.x 🐞 / PHP 7.4 Test on ubuntu-latest (push) Canceled after 0s
PHP-CS-Fixer / composer_install (7.4) (push) Canceled after 0s
Chamilo 1.11.40 (ZIP oficial v1.11.40)
Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip
sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439
Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
2026-08-06 17:59:45 +02:00

66 lines
1.9 KiB
PHP

<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Client\Http;
use Xabbuh\XApi\Model\Attachment;
/**
* HTTP message body containing serialized statements and their attachments.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class MultipartStatementBody
{
private $boundary;
private $serializedStatements;
private $attachments;
/**
* @param string $serializedStatements The JSON encoded statement(s)
* @param Attachment[] $attachments The statement attachments that include not only a file URL
*/
public function __construct($serializedStatements, array $attachments)
{
$this->boundary = uniqid();
$this->serializedStatements = $serializedStatements;
$this->attachments = $attachments;
}
public function getBoundary()
{
return $this->boundary;
}
public function build()
{
$body = '--'.$this->boundary."\r\n";
$body .= "Content-Type: application/json\r\n";
$body .= 'Content-Length: '.strlen($this->serializedStatements)."\r\n";
$body .= "\r\n";
$body .= $this->serializedStatements."\r\n";
foreach ($this->attachments as $attachment) {
$body .= '--'.$this->boundary."\r\n";
$body .= 'Content-Type: '.$attachment->getContentType()."\r\n";
$body .= "Content-Transfer-Encoding: binary\r\n";
$body .= 'Content-Length: '.$attachment->getLength()."\r\n";
$body .= 'X-Experience-API-Hash: '.$attachment->getSha2()."\r\n";
$body .= "\r\n";
$body .= $attachment->getContent()."\r\n";
}
$body .= '--'.$this->boundary.'--'."\r\n";
return $body;
}
}