1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00

upload wip

This commit is contained in:
Robin Appelman 2017-01-31 13:34:54 +01:00
commit fca5d7b0a6
15 changed files with 2146 additions and 164 deletions

42
Demo/AzureStore.php Normal file
View file

@ -0,0 +1,42 @@
<?php namespace Demo;
use MicrosoftAzure\Storage\Blob\Internal\IBlob;
class AzureStore implements IDemoStore {
/**
* @var IBlob
*/
private $blobStorage;
/**
* @param IBlob $blobStorage
*/
public function __construct(IBlob $blobStorage) {
$this->blobStorage = $blobStorage;
}
/**
* @param resource $stream
* @param string $name
* @return StoredDemo
*/
public function store($stream, $name) {
$name = preg_replace("/[^A-Za-z0-9\\.\\-]/", '', $name);
if (substr($name, -4) !== '.dem') {
$name .= '.dem';
}
$id = uniqid() . $name;
$this->upload($stream, $id);
$url = 'https://demostf.blob.core.windows.net/demos/' . $id;
return new StoredDemo('azure', $id, $url);
}
/**
* @param resource $stream
* @param string $id
* @return string mixed
*/
private function upload($stream, $id) {
$this->blobStorage->createBlockBlob('demos', $id, $stream);
}
}