appwrite/src/Appwrite/Specification/Format.php

130 lines
2.8 KiB
PHP
Raw Normal View History

2020-11-11 22:02:42 +00:00
<?php
namespace Appwrite\Specification;
use Utopia\App;
use Utopia\Route;
use Appwrite\Utopia\Response\Model;
abstract class Format
{
protected App $app;
2022-05-23 14:54:50 +00:00
2020-11-11 22:02:42 +00:00
/**
* @var Route[]
*/
protected array $routes;
2022-05-23 14:54:50 +00:00
2020-11-11 22:02:42 +00:00
/**
* @var Model[]
*/
protected array $models;
2022-05-23 14:54:50 +00:00
protected array $services;
protected array $keys;
protected int $authCount;
protected array $params = [
2020-11-11 22:02:42 +00:00
'name' => '',
'description' => '',
'endpoint' => 'https://localhost',
'version' => '1.0.0',
'terms' => '',
'support.email' => '',
'support.url' => '',
'contact.name' => '',
'contact.email' => '',
'contact.url' => '',
'license.name' => '',
'license.url' => '',
];
public function __construct(App $app, array $services, array $routes, array $models, array $keys, int $authCount)
2020-11-11 22:02:42 +00:00
{
$this->app = $app;
$this->services = $services;
2020-11-11 22:02:42 +00:00
$this->routes = $routes;
$this->models = $models;
$this->keys = $keys;
2021-05-19 14:26:06 +00:00
$this->authCount = $authCount;
2020-11-11 22:02:42 +00:00
}
/**
* Get Name.
*
* Get format name
*
* @return string
*/
abstract public function getName(): string;
/**
* Parse
*
* Parses Appwrite App to given format
*
* @return array
*/
abstract public function parse(): array;
/**
* Set Param.
*
* Set param value
*
* @param string $key
* @param string $value
2022-05-23 14:54:50 +00:00
*
2020-11-11 22:02:42 +00:00
* @return self
*/
public function setParam(string $key, string $value): self
{
$this->params[$key] = $value;
return $this;
}
/**
* Get Param.
*
* Get param value
*
* @param string $key
* @param string $default
2022-05-23 14:54:50 +00:00
*
2020-11-11 22:02:42 +00:00
* @return string
*/
public function getParam(string $key, string $default = ''): string
{
return $this->params[$key] ?? $default;
2020-11-11 22:02:42 +00:00
}
2023-07-13 16:21:22 +00:00
protected function getEnumName(string $service, string $method): ?string
{
switch ($service) {
case 'account':
switch ($method) {
case 'createOAuth2Session':
return 'Provider';
}
break;
case 'avatars':
switch ($method) {
case 'getBrowser':
return 'Browser';
case 'getCreditCard':
return 'CreditCard';
case 'getFlag':
return 'Flag';
}
2023-07-18 04:23:39 +00:00
break;
case 'storage':
switch ($method) {
case 'getFilePreview':
return 'ImageGravity';
}
break;
2023-07-13 16:21:22 +00:00
}
return null;
}
2020-11-11 22:02:42 +00:00
}