Updated src folder
This commit is contained in:
parent
b79188a07e
commit
6392ceef55
|
@ -9,9 +9,14 @@ use Appwrite\Auth\OAuth2;
|
||||||
|
|
||||||
class Box extends OAuth2
|
class Box extends OAuth2
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
private $endpoint = 'https://account.box.com/api/oauth2/';
|
private $endpoint = 'https://account.box.com/api/oauth2/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
private $resourceEndpoint = 'https://api.box.com/2.0/';
|
private $resourceEndpoint = 'https://api.box.com/2.0/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +24,9 @@ class Box extends OAuth2
|
||||||
*/
|
*/
|
||||||
protected $user = [];
|
protected $user = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
protected $scopes = [
|
protected $scopes = [
|
||||||
'manage_app_users',
|
'manage_app_users',
|
||||||
];
|
];
|
||||||
|
@ -148,5 +156,4 @@ class Box extends OAuth2
|
||||||
|
|
||||||
return $this->user;
|
return $this->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -125,7 +125,7 @@ class Github extends OAuth2
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getUser(string $accessToken)
|
protected function getUser(string $accessToken)
|
||||||
{
|
{
|
||||||
if (empty($this->user)) {
|
if (empty($this->user)) {
|
||||||
$this->user = \json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token '.\urlencode($accessToken)]), true);
|
$this->user = \json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token '.\urlencode($accessToken)]), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ class MySQL extends Adapter
|
||||||
|
|
||||||
// Handle array of relations
|
// Handle array of relations
|
||||||
if (self::DATA_TYPE_ARRAY === $type) {
|
if (self::DATA_TYPE_ARRAY === $type) {
|
||||||
if(!is_array($value)) { // Property should be of type array, if not = skip
|
if (!is_array($value)) { // Property should be of type array, if not = skip
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -452,7 +452,7 @@ class Database
|
||||||
$filters = $rule->getAttribute('filter', null);
|
$filters = $rule->getAttribute('filter', null);
|
||||||
$value = $document->getAttribute($key, null);
|
$value = $document->getAttribute($key, null);
|
||||||
|
|
||||||
if(($value !== null) && is_array($filters)) {
|
if (($value !== null) && is_array($filters)) {
|
||||||
foreach ($filters as $filter) {
|
foreach ($filters as $filter) {
|
||||||
$value = $this->encodeAttribute($filter, $value);
|
$value = $this->encodeAttribute($filter, $value);
|
||||||
$document->setAttribute($key, $value);
|
$document->setAttribute($key, $value);
|
||||||
|
@ -473,7 +473,7 @@ class Database
|
||||||
$filters = $rule->getAttribute('filter', null);
|
$filters = $rule->getAttribute('filter', null);
|
||||||
$value = $document->getAttribute($key, null);
|
$value = $document->getAttribute($key, null);
|
||||||
|
|
||||||
if(($value !== null) && is_array($filters)) {
|
if (($value !== null) && is_array($filters)) {
|
||||||
foreach (array_reverse($filters) as $filter) {
|
foreach (array_reverse($filters) as $filter) {
|
||||||
$value = $this->decodeAttribute($filter, $value);
|
$value = $this->decodeAttribute($filter, $value);
|
||||||
$document->setAttribute($key, $value);
|
$document->setAttribute($key, $value);
|
||||||
|
@ -492,7 +492,7 @@ class Database
|
||||||
*/
|
*/
|
||||||
static protected function encodeAttribute(string $name, $value)
|
static protected function encodeAttribute(string $name, $value)
|
||||||
{
|
{
|
||||||
if(!isset(self::$filters[$name])) {
|
if (!isset(self::$filters[$name])) {
|
||||||
throw new Exception('Filter not found');
|
throw new Exception('Filter not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,7 +513,7 @@ class Database
|
||||||
*/
|
*/
|
||||||
static protected function decodeAttribute(string $name, $value)
|
static protected function decodeAttribute(string $name, $value)
|
||||||
{
|
{
|
||||||
if(!isset(self::$filters[$name])) {
|
if (!isset(self::$filters[$name])) {
|
||||||
throw new Exception('Filter not found');
|
throw new Exception('Filter not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ class Structure extends Validator
|
||||||
foreach ($array as $key => $value) {
|
foreach ($array as $key => $value) {
|
||||||
$rule = $collection->search('key', $key, $rules);
|
$rule = $collection->search('key', $key, $rules);
|
||||||
|
|
||||||
if(!$rule) {
|
if (!$rule) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ class UID extends Validator
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mb_strlen($value) > 32) {
|
if (mb_strlen($value) > 32) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Compose
|
||||||
*/
|
*/
|
||||||
public function getService(string $name): Service
|
public function getService(string $name): Service
|
||||||
{
|
{
|
||||||
if(!isset($this->compose['services'][$name])) {
|
if (!isset($this->compose['services'][$name])) {
|
||||||
throw new Exception('Service not found');
|
throw new Exception('Service not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,15 +16,14 @@ class Env
|
||||||
*/
|
*/
|
||||||
public function __construct(string $data)
|
public function __construct(string $data)
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = explode("\n", $data);
|
$data = explode("\n", $data);
|
||||||
|
|
||||||
foreach($data as &$row) {
|
foreach ($data as &$row) {
|
||||||
$row = explode('=', $row);
|
$row = explode('=', $row);
|
||||||
$key = (isset($row[0])) ? trim($row[0]) : null;
|
$key = (isset($row[0])) ? trim($row[0]) : null;
|
||||||
$value = (isset($row[1])) ? trim($row[1]) : null;
|
$value = (isset($row[1])) ? trim($row[1]) : null;
|
||||||
|
|
||||||
if($key) {
|
if ($key) {
|
||||||
$this->vars[$key] = $value;
|
$this->vars[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,15 +73,15 @@ class PDOStatement extends PDOStatementNative
|
||||||
$this->pdo = $this->pdo->reconnect();
|
$this->pdo = $this->pdo->reconnect();
|
||||||
$this->PDOStatement = $this->pdo->prepare($this->PDOStatement->queryString, []);
|
$this->PDOStatement = $this->pdo->prepare($this->PDOStatement->queryString, []);
|
||||||
|
|
||||||
foreach($this->values as $key => $set) {
|
foreach ($this->values as $key => $set) {
|
||||||
$this->PDOStatement->bindValue($key, $set['value'], $set['data_type']);
|
$this->PDOStatement->bindValue($key, $set['value'], $set['data_type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->params as $key => $set) {
|
foreach ($this->params as $key => $set) {
|
||||||
$this->PDOStatement->bindParam($key, $set['variable'], $set['data_type'], $set['length'], $set['driver_options']);
|
$this->PDOStatement->bindParam($key, $set['variable'], $set['data_type'], $set['length'], $set['driver_options']);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->columns as $key => $set) {
|
foreach ($this->columns as $key => $set) {
|
||||||
$this->PDOStatement->bindColumn($key, $set['param'], $set['type'], $set['maxlen'], $set['driverdata']);
|
$this->PDOStatement->bindColumn($key, $set['param'], $set['type'], $set['maxlen'], $set['driverdata']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class CNAME extends Validator
|
||||||
*/
|
*/
|
||||||
public function isValid($domain)
|
public function isValid($domain)
|
||||||
{
|
{
|
||||||
if(!is_string($domain)) {
|
if (!is_string($domain)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,11 @@ class Domain extends Validator
|
||||||
*/
|
*/
|
||||||
public function isValid($value)
|
public function isValid($value)
|
||||||
{
|
{
|
||||||
if(empty($value)) {
|
if (empty($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ class Origin extends Validator
|
||||||
*/
|
*/
|
||||||
public function isValid($origin)
|
public function isValid($origin)
|
||||||
{
|
{
|
||||||
if(!is_string($origin)) {
|
if (!is_string($origin)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class FileName extends Validator
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_string($name)) {
|
if (!is_string($name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class FileSize extends Validator
|
||||||
*/
|
*/
|
||||||
public function isValid($fileSize)
|
public function isValid($fileSize)
|
||||||
{
|
{
|
||||||
if(!is_int($fileSize)) {
|
if (!is_int($fileSize)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Upload extends Validator
|
||||||
*/
|
*/
|
||||||
public function isValid($path)
|
public function isValid($path)
|
||||||
{
|
{
|
||||||
if(!is_string($path)) {
|
if (!is_string($path)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Files
|
||||||
*/
|
*/
|
||||||
public static function removeMimeType(string $mimeType): void
|
public static function removeMimeType(string $mimeType): void
|
||||||
{
|
{
|
||||||
if(isset(self::$mimeTypes[$mimeType])) {
|
if (isset(self::$mimeTypes[$mimeType])) {
|
||||||
unset(self::$mimeTypes[$mimeType]);
|
unset(self::$mimeTypes[$mimeType]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ class Files
|
||||||
*/
|
*/
|
||||||
public static function load(string $directory, string $root = null): void
|
public static function load(string $directory, string $root = null): void
|
||||||
{
|
{
|
||||||
if(!is_readable($directory)) {
|
if (!is_readable($directory)) {
|
||||||
throw new Exception('Failed to load directory: '.$directory);
|
throw new Exception('Failed to load directory: '.$directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ class Files
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(substr($path, 0, 1) === '.') {
|
if (substr($path, 0, 1) === '.') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ class Files
|
||||||
|
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
|
|
||||||
if($directory === $root) {
|
if ($directory === $root) {
|
||||||
echo '[Static Files] Loadded '.self::$count.' files'.PHP_EOL;
|
echo '[Static Files] Loadded '.self::$count.' files'.PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ class Files
|
||||||
*/
|
*/
|
||||||
public static function isFileLoaded(string $uri): bool
|
public static function isFileLoaded(string $uri): bool
|
||||||
{
|
{
|
||||||
if(!array_key_exists($uri, self::$loaded)) {
|
if (!array_key_exists($uri, self::$loaded)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ class Files
|
||||||
*/
|
*/
|
||||||
public static function getFileContents(string $uri): string
|
public static function getFileContents(string $uri): string
|
||||||
{
|
{
|
||||||
if(!array_key_exists($uri, self::$loaded)) {
|
if (!array_key_exists($uri, self::$loaded)) {
|
||||||
throw new Exception('File not found or not loaded: '.$uri);
|
throw new Exception('File not found or not loaded: '.$uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ class Files
|
||||||
*/
|
*/
|
||||||
public static function getFileMimeType(string $uri): string
|
public static function getFileMimeType(string $uri): string
|
||||||
{
|
{
|
||||||
if(!array_key_exists($uri, self::$loaded)) {
|
if (!array_key_exists($uri, self::$loaded)) {
|
||||||
throw new Exception('File not found or not loaded: '.$uri);
|
throw new Exception('File not found or not loaded: '.$uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Request extends UtopiaRequest
|
||||||
*/
|
*/
|
||||||
public function getParam(string $key, $default = null)
|
public function getParam(string $key, $default = null)
|
||||||
{
|
{
|
||||||
switch($this->getMethod()) {
|
switch ($this->getMethod()) {
|
||||||
case self::METHOD_GET:
|
case self::METHOD_GET:
|
||||||
return $this->getQuery($key, $default);
|
return $this->getQuery($key, $default);
|
||||||
break;
|
break;
|
||||||
|
@ -57,7 +57,7 @@ class Request extends UtopiaRequest
|
||||||
*/
|
*/
|
||||||
public function getParams(): array
|
public function getParams(): array
|
||||||
{
|
{
|
||||||
switch($this->getMethod()) {
|
switch ($this->getMethod()) {
|
||||||
case self::METHOD_GET:
|
case self::METHOD_GET:
|
||||||
return (!empty($this->swoole->get)) ? $this->swoole->get : [];
|
return (!empty($this->swoole->get)) ? $this->swoole->get : [];
|
||||||
break;
|
break;
|
||||||
|
@ -143,7 +143,7 @@ class Request extends UtopiaRequest
|
||||||
{
|
{
|
||||||
$protocol = $this->getHeader('x-forwarded-proto', $this->getServer('server_protocol', 'https'));
|
$protocol = $this->getHeader('x-forwarded-proto', $this->getServer('server_protocol', 'https'));
|
||||||
|
|
||||||
if($protocol === 'HTTP/1.1') {
|
if ($protocol === 'HTTP/1.1') {
|
||||||
return 'http';
|
return 'http';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ class Request extends UtopiaRequest
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed
|
if (empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed
|
||||||
$this->payload = [];
|
$this->payload = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class Response extends UtopiaResponse
|
||||||
* Response constructor.
|
* Response constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct(SwooleResponse $response)
|
public function __construct(SwooleResponse $response)
|
||||||
{
|
{
|
||||||
$this->swoole = $response;
|
$this->swoole = $response;
|
||||||
parent::__construct(\microtime(true));
|
parent::__construct(\microtime(true));
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ class Response extends UtopiaResponse
|
||||||
*/
|
*/
|
||||||
public function send(string $body = '', int $exit = null): void
|
public function send(string $body = '', int $exit = null): void
|
||||||
{
|
{
|
||||||
if(!$this->disablePayload) {
|
if (!$this->disablePayload) {
|
||||||
$this->addHeader('X-Debug-Speed', (string)(microtime(true) - $this->startTime));
|
$this->addHeader('X-Debug-Speed', (string)(microtime(true) - $this->startTime));
|
||||||
|
|
||||||
$this
|
$this
|
||||||
|
@ -67,13 +67,12 @@ class Response extends UtopiaResponse
|
||||||
|
|
||||||
$this->size = $this->size + strlen(implode("\n", $this->headers)) + $length;
|
$this->size = $this->size + strlen(implode("\n", $this->headers)) + $length;
|
||||||
|
|
||||||
if(array_key_exists(
|
if (array_key_exists(
|
||||||
$this->contentType,
|
$this->contentType,
|
||||||
$this->compressed
|
$this->compressed
|
||||||
) && ($length <= $chunk)) { // Dont compress with GZIP / Brotli if header is not listed and size is bigger than 2mb
|
) && ($length <= $chunk)) { // Dont compress with GZIP / Brotli if header is not listed and size is bigger than 2mb
|
||||||
$this->swoole->end($body);
|
$this->swoole->end($body);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for ($i=0; $i < ceil($length / $chunk); $i++) {
|
for ($i=0; $i < ceil($length / $chunk); $i++) {
|
||||||
$this->swoole->write(substr($body, ($i * $chunk), min((($i * $chunk) + $chunk), $length)));
|
$this->swoole->write(substr($body, ($i * $chunk), min((($i * $chunk) + $chunk), $length)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Cron extends Validator
|
||||||
*/
|
*/
|
||||||
public function isValid($value)
|
public function isValid($value)
|
||||||
{
|
{
|
||||||
if(empty($value)) {
|
if (empty($value)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ class Response extends UtopiaResponse
|
||||||
*/
|
*/
|
||||||
public function getModel(string $key): Model
|
public function getModel(string $key): Model
|
||||||
{
|
{
|
||||||
if(!isset($this->models[$key])) {
|
if (!isset($this->models[$key])) {
|
||||||
throw new Exception('Undefined model: '.$key);
|
throw new Exception('Undefined model: '.$key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,23 +126,22 @@ class Response extends UtopiaResponse
|
||||||
$model = $this->getModel($model);
|
$model = $this->getModel($model);
|
||||||
$output = [];
|
$output = [];
|
||||||
|
|
||||||
foreach($model->getRules() as $key => $rule) {
|
foreach ($model->getRules() as $key => $rule) {
|
||||||
if(!$document->isSet($key)) {
|
if (!$document->isSet($key)) {
|
||||||
if(!is_null($rule['default'])) {
|
if (!is_null($rule['default'])) {
|
||||||
$document->setAttribute($key, $rule['default']);
|
$document->setAttribute($key, $rule['default']);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new Exception('Missing response key: '.$key);
|
throw new Exception('Missing response key: '.$key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($rule['array']) {
|
if ($rule['array']) {
|
||||||
if(!is_array($data[$key])) {
|
if (!is_array($data[$key])) {
|
||||||
throw new Exception($key.' must be an array of '.$rule['type'].' types');
|
throw new Exception($key.' must be an array of '.$rule['type'].' types');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data[$key] as &$item) {
|
foreach ($data[$key] as &$item) {
|
||||||
if(array_key_exists($rule['type'], $this->models) && $item instanceof Document) {
|
if (array_key_exists($rule['type'], $this->models) && $item instanceof Document) {
|
||||||
$item = $this->output($item, $rule['type']);
|
$item = $this->output($item, $rule['type']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,7 +167,7 @@ class Response extends UtopiaResponse
|
||||||
*/
|
*/
|
||||||
public function yaml(array $data): void
|
public function yaml(array $data): void
|
||||||
{
|
{
|
||||||
if(!extension_loaded('yaml')) {
|
if (!extension_loaded('yaml')) {
|
||||||
throw new Exception('Missing yaml extension. Learn more at: https://www.php.net/manual/en/book.yaml.php');
|
throw new Exception('Missing yaml extension. Learn more at: https://www.php.net/manual/en/book.yaml.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ class File extends Model
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue