1. Go to this page and download the library: Download zdenekgebauer/dosiero library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zdenekgebauer / dosiero example snippets
declare(strict_types=1);
// entry point of the server part of the connector; see "Protocol" below for the request
// and response format
namespace Dosiero;
// uncomment for debugging
// error_reporting(E_ALL);
// ini_set('display_errors', 'on');
use Exception;
use Dosiero\Local\LocalStorage;
config->::OPTION_MODE_DIRECTORY, 0775);
$localStorage->setOption(LocalStorage::OPTION_MODE_FILE, 0664);
try {
$connector = new Connector($config);
$connector->addStorage($localStorage);
$response = $connector->handleRequest();
} catch (AccessForbiddenException $exception) {
$response = new Response(403, $exception->getMessage());
} catch (StorageException $exception) {
$response = new Response(400, $exception->getMessage());
} catch (InvalidRequestException $exception) {
$response = new Response(400, $exception->getMessage());
} catch (Exception $exception) {
$response = new Response(500, 'unexpected problem: ' . $exception->getMessage());
}
// origins come from Config, so an error response carries the same headers as a successful one
$response->allowAccessFrom($config);
// a browser asks before it will send a cross-origin request carrying the protocol header
if (!$response->sendPreflight()) {
$response->sendOutput();
}
final class FilesController
{
public function handleRequest(): ResponseInterface // your framework's response
{
// the connector below filters storages per caller, so for action=storages an anonymous
// request would get an empty inventory and 200 rather than being turned away
if ($this->application->currentUser() === null) {
return $this->json(403, ['msg' => 'access denied']);
}
$config = new \Dosiero\Config();
$config->o\InvalidRequestException $exception) {
$response = new \Dosiero\Response(400, $exception->getMessage());
}
return $this->json($response->getHttpStatus(), $response->toStdClass());
}
}
$config = new Config();
$config->', '42'); // a session variable and its value
$config->setAllowedIp(['127.0.0.1', '10.0.0.0/8']); // single addresses or CIDR ranges
$config->allowAnonymous(); // deliberately public, e.g. a demo
$config->$action === 'files' || $action === 'storages') {
return true; // everybody may look
}
return Auth::user()?->isEditor() === true; // only editors may change
});
$config->allowOrigin('https://app.example.org');
// or, when the client has to send cookies or basic auth:
$config->allowOrigin('https://app.example.org', true);
$response->allowAccessFrom($config);
if (!$response->sendPreflight()) {
$response->sendOutput();
}