1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-10 15:14:20 +02:00

feat(endpoints): use Atomastic Components #478

This commit is contained in:
Awilum
2020-11-23 23:20:54 +03:00
parent b56a4842cf
commit 68af916c7b
16 changed files with 164 additions and 172 deletions

View File

@@ -14,5 +14,5 @@ namespace Flextype;
*/
function validate_access_token($token) : bool
{
return flextype('filesystem')->file(PATH['project'] . '/tokens/access/' . $token . '/token.yaml')->exists();
return filesystem()->file(PATH['project'] . '/tokens/access/' . $token . '/token.yaml')->exists();
}

View File

@@ -21,7 +21,7 @@ use function is_array;
*/
function validate_entries_token($token) : bool
{
return flextype('filesystem')->file(PATH['project'] . '/tokens/entries/' . $token . '/token.yaml')->exists();
return filesystem()->file(PATH['project'] . '/tokens/entries/' . $token . '/token.yaml')->exists();
}
/**
@@ -59,7 +59,7 @@ flextype()->get('/api/entries', function (Request $request, Response $response)
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
// Set entries token file
if ($entries_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($entries_token_file_path)->get())) {
if ($entries_token_file_data = flextype('yaml')->decode(filesystem()->file($entries_token_file_path)->get())) {
if ($entries_token_file_data['state'] === 'disabled' ||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
return $response
@@ -154,8 +154,8 @@ flextype()->post('/api/entries', function (Request $request, Response $response)
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set entries and access token file
if (($entries_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($entries_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($entries_token_file_data = flextype('yaml')->decode(filesystem()->file($entries_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($entries_token_file_data['state'] === 'disabled' ||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
return $response
@@ -258,8 +258,8 @@ flextype()->patch('/api/entries', function (Request $request, Response $response
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set entries and access token file
if (($entries_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($entries_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($entries_token_file_data = flextype('yaml')->decode(filesystem()->file($entries_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($entries_token_file_data['state'] === 'disabled' ||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
return $response
@@ -289,7 +289,7 @@ flextype()->patch('/api/entries', function (Request $request, Response $response
$response_code = $update_entry ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($entries_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1])));
filesystem()->file($entries_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -362,8 +362,8 @@ flextype()->put('/api/entries', function (Request $request, Response $response)
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set entries and access token file
if (($entries_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($entries_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($entries_token_file_data = flextype('yaml')->decode(filesystem()->file($entries_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($entries_token_file_data['state'] === 'disabled' ||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
return $response
@@ -394,7 +394,7 @@ flextype()->put('/api/entries', function (Request $request, Response $response)
$response_code = $rename_entry ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($entries_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1])));
filesystem()->file($entries_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -467,8 +467,8 @@ flextype()->put('/api/entries/copy', function (Request $request, Response $respo
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set entries and access token file
if (($entries_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($entries_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($entries_token_file_data = flextype('yaml')->decode(filesystem()->file($entries_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($entries_token_file_data['state'] === 'disabled' ||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
return $response
@@ -499,7 +499,7 @@ flextype()->put('/api/entries/copy', function (Request $request, Response $respo
$response_code = $copy_entry === null ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($entries_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1])));
filesystem()->file($entries_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -570,8 +570,8 @@ flextype()->delete('/api/entries', function (Request $request, Response $respons
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set entries and access token file
if (($entries_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($entries_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($entries_token_file_data = flextype('yaml')->decode(filesystem()->file($entries_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($entries_token_file_data['state'] === 'disabled' ||
($entries_token_file_data['limit_calls'] !== 0 && $entries_token_file_data['calls'] >= $entries_token_file_data['limit_calls'])) {
return $response
@@ -595,7 +595,7 @@ flextype()->delete('/api/entries', function (Request $request, Response $respons
$response_code = $delete_entry ? 204 : 404;
// Update calls counter
flextype('filesystem')->file($entries_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1])));
filesystem()->file($entries_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response

View File

@@ -21,7 +21,7 @@ use function is_dir;
*/
function validate_files_token($token) : bool
{
return flextype('filesystem')->file(PATH['project'] . '/tokens/files/' . $token . '/token.yaml')->exists();
return filesystem()->file(PATH['project'] . '/tokens/files/' . $token . '/token.yaml')->exists();
}
/**
@@ -56,7 +56,7 @@ flextype()->get('/api/files', function (Request $request, Response $response) us
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
// Set delivery token file
if ($files_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($files_token_file_path)->get())) {
if ($files_token_file_data = flextype('yaml')->decode(filesystem()->file($files_token_file_path)->get())) {
if ($files_token_file_data['state'] === 'disabled' ||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
return $response
@@ -83,7 +83,7 @@ flextype()->get('/api/files', function (Request $request, Response $response) us
$response_code = count($response_data['data']) > 0 ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($files_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
filesystem()->file($files_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -155,8 +155,8 @@ flextype()->post('/api/files', function (Request $request, Response $response) u
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set files and access token file
if (($files_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($files_token_file_data = flextype('yaml')->decode(filesystem()->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($files_token_file_data['state'] === 'disabled' ||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
return $response
@@ -183,10 +183,10 @@ flextype()->post('/api/files', function (Request $request, Response $response) u
}
// Set response code
$response_code = flextype('filesystem')->file($create_file)->exists() ? 200 : 404;
$response_code = filesystem()->file($create_file)->exists() ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($files_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
filesystem()->file($files_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -259,8 +259,8 @@ flextype()->put('/api/files', function (Request $request, Response $response) us
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set files and access token file
if (($files_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($files_token_file_data = flextype('yaml')->decode(filesystem()->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($files_token_file_data['state'] === 'disabled' ||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
return $response
@@ -290,7 +290,7 @@ flextype()->put('/api/files', function (Request $request, Response $response) us
$response_code = $rename_file === true ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($files_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
filesystem()->file($files_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -362,8 +362,8 @@ flextype()->put('/api/files/copy', function (Request $request, Response $respons
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set files and access token file
if (($files_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($files_token_file_data = flextype('yaml')->decode(filesystem()->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($files_token_file_data['state'] === 'disabled' ||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
return $response
@@ -463,8 +463,8 @@ flextype()->delete('/api/files', function (Request $request, Response $response)
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set files and access token file
if (($files_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($files_token_file_data = flextype('yaml')->decode(filesystem()->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($files_token_file_data['state'] === 'disabled' ||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
return $response
@@ -488,7 +488,7 @@ flextype()->delete('/api/files', function (Request $request, Response $response)
$response_code = $delete_file ? 204 : 404;
// Update calls counter
flextype('filesystem')->file($files_token_file_path)->get(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
filesystem()->file($files_token_file_path)->get(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -562,7 +562,7 @@ flextype()->patch('/api/files/meta', function (Request $request, Response $respo
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set files and access token file
if (($files_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($files_token_file_path)->get())) &&
if (($files_token_file_data = flextype('yaml')->decode(filesystem()->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesytem')->file($access_token_file_path)->get($access_token_file_path)))) {
if ($files_token_file_data['state'] === 'disabled' ||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
@@ -593,7 +593,7 @@ flextype()->patch('/api/files/meta', function (Request $request, Response $respo
$response_code = $update_file_meta ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($files_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
filesystem()->file($files_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -667,8 +667,8 @@ flextype()->post('/api/files/meta', function (Request $request, Response $respon
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set files and access token file
if (($files_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($files_token_file_data = flextype('yaml')->decode(filesystem()->file($files_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($files_token_file_data['state'] === 'disabled' ||
($files_token_file_data['limit_calls'] !== 0 && $files_token_file_data['calls'] >= $files_token_file_data['limit_calls'])) {
return $response
@@ -698,7 +698,7 @@ flextype()->post('/api/files/meta', function (Request $request, Response $respon
$response_code = $add_file_meta ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($files_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
filesystem()->file($files_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response

View File

@@ -19,7 +19,7 @@ use function count;
*/
function validate_folders_token($token) : bool
{
return flextype('filesystem')->file(PATH['project'] . '/tokens/folders/' . $token . '/token.yaml')->exists();
return filesystem()->file(PATH['project'] . '/tokens/folders/' . $token . '/token.yaml')->exists();
}
/**
@@ -91,7 +91,7 @@ flextype()->get('/api/folders', function (Request $request, Response $response)
$response_code = count($response_data['data']) > 0 ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($folders_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1])));
filesystem()->file($folders_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -162,8 +162,8 @@ flextype()->post('/api/folders', function (Request $request, Response $response)
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set files and access token file
if (($folders_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($folders_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($folders_token_file_data = flextype('yaml')->decode(filesystem()->file($folders_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($folders_token_file_data['state'] === 'disabled' ||
($folders_token_file_data['limit_calls'] !== 0 && $folders_token_file_data['calls'] >= $folders_token_file_data['limit_calls'])) {
return $response->withStatus($api_errors['0501']['http_status_code'])
@@ -191,7 +191,7 @@ flextype()->post('/api/folders', function (Request $request, Response $response)
$response_code = $create_folder ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($folders_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1])));
filesystem()->file($folders_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -263,8 +263,8 @@ flextype()->put('/api/folders/copy', function (Request $request, Response $respo
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set files and access token file
if (($folders_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($folders_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($folders_token_file_data = flextype('yaml')->decode(filesystem()->file($folders_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($folders_token_file_data['state'] === 'disabled' ||
($folders_token_file_data['limit_calls'] !== 0 && $folders_token_file_data['calls'] >= $folders_token_file_data['limit_calls'])) {
return $response->withStatus($api_errors['0601']['http_status_code'])
@@ -294,7 +294,7 @@ flextype()->put('/api/folders/copy', function (Request $request, Response $respo
$response_code = $copy_folder ? 200 : 404;
// Update calls counter
flextype('filesystem')->file($folders_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1])));
filesystem()->file($folders_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response
@@ -366,8 +366,8 @@ flextype()->put('/api/folders', function (Request $request, Response $response)
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set files and access token file
if (($folders_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($folders_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($folders_token_file_data = flextype('yaml')->decode(filesystem()->file($folders_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($folders_token_file_data['state'] === 'disabled' ||
($folders_token_file_data['limit_calls'] !== 0 && $folders_token_file_data['calls'] >= $folders_token_file_data['limit_calls'])) {
return $response->withStatus($api_errors['0501']['http_status_code'])
@@ -465,8 +465,8 @@ flextype()->delete('/api/folders', function (Request $request, Response $respons
$access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml';
// Set files and access token file
if (($folders_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($folders_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($access_token_file_path)->get()))) {
if (($folders_token_file_data = flextype('yaml')->decode(filesystem()->file($folders_token_file_path)->get())) &&
($access_token_file_data = flextype('yaml')->decode(filesystem()->file($access_token_file_path)->get()))) {
if ($folders_token_file_data['state'] === 'disabled' ||
($folders_token_file_data['limit_calls'] !== 0 && $folders_token_file_data['calls'] >= $folders_token_file_data['limit_calls'])) {
return $response->withStatus($api_errors['0501']['http_status_code'])
@@ -488,7 +488,7 @@ flextype()->delete('/api/folders', function (Request $request, Response $respons
$response_code = $delete_folder ? 204 : 404;
// Update calls counter
flextype('filesystem')->file($folders_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1])));
filesystem()->file($folders_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1])));
if ($response_code === 404) {
// Return response

View File

@@ -18,7 +18,7 @@ use function array_replace_recursive;
*/
function validate_images_token($token) : bool
{
return flextype('filesystem')->file(PATH['project'] . '/tokens/images/' . $token . '/token.yaml')->exists();
return filesystem()->file(PATH['project'] . '/tokens/images/' . $token . '/token.yaml')->exists();
}
/**
@@ -54,7 +54,7 @@ flextype()->get('/api/images/{path:.+}', function (Request $request, Response $r
$delivery_images_token_file_path = PATH['project'] . '/tokens/images/' . $token . '/token.yaml';
// Set delivery token file
if ($delivery_images_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($delivery_images_token_file_path)->get())) {
if ($delivery_images_token_file_data = flextype('yaml')->decode(filesystem()->file($delivery_images_token_file_path)->get())) {
if ($delivery_images_token_file_data['state'] === 'disabled' ||
($delivery_images_token_file_data['limit_calls'] !== 0 && $delivery_images_token_file_data['calls'] >= $delivery_images_token_file_data['limit_calls'])) {
return $response->withStatus($api_errors['0003']['http_status_code'])
@@ -65,7 +65,7 @@ flextype()->get('/api/images/{path:.+}', function (Request $request, Response $r
// Update calls counter
flextype('filesytem')->file($delivery_images_token_file_path)->put(flextype('yaml')->encode(array_replace_recursive($delivery_images_token_file_data, ['calls' => $delivery_images_token_file_data['calls'] + 1])));
if (flextype('filesystem')->file(PATH['project'] . '/uploads/entries/' . $args['path'])->exists()) {
if (filesystem()->file(PATH['project'] . '/uploads/entries/' . $args['path'])->exists()) {
return flextype('images')->getImageResponse($args['path'], $_GET);
}

View File

@@ -18,7 +18,7 @@ use function array_replace_recursive;
*/
function validate_registry_token($token) : bool
{
return flextype('filesystem')->file(PATH['project'] . '/tokens/registry/' . $token . '/token.yaml')->exists();
return filesystem()->file(PATH['project'] . '/tokens/registry/' . $token . '/token.yaml')->exists();
}
/**
@@ -53,7 +53,7 @@ flextype()->get('/api/registry', function (Request $request, Response $response)
$registry_token_file_path = PATH['project'] . '/tokens/registry/' . $token . '/token.yaml';
// Set token file
if ($registry_token_file_data = flextype('yaml')->decode(flextype('filesystem')->file($registry_token_file_path)->get())) {
if ($registry_token_file_data = flextype('yaml')->decode(filesystem()->file($registry_token_file_path)->get())) {
if ($registry_token_file_data['state'] === 'disabled' ||
($registry_token_file_data['limit_calls'] !== 0 && $registry_token_file_data['calls'] >= $registry_token_file_data['limit_calls'])) {
return $response->withStatus($api_errors['0003']['http_status_code'])
@@ -74,7 +74,7 @@ flextype()->get('/api/registry', function (Request $request, Response $response)
}
// Update calls counter
flextype('filesystem')->file($registry_token_file_path)
filesystem()->file($registry_token_file_path)
->put(flextype('yaml')->encode(array_replace_recursive($registry_token_file_data, ['calls' => $registry_token_file_data['calls'] + 1])));
if ($response_code === 404) {

View File

@@ -112,7 +112,7 @@ class Entries
$entry_file = $this->getFileLocation($this->storage['fetch_single']['id']);
// Try to get requested entry from the filesystem
$entry_file_content = flextype('filesystem')->file($entry_file)->get();
$entry_file_content = filesystem()->file($entry_file)->get();
if ($entry_file_content === false) {
return [];
}
@@ -207,7 +207,7 @@ class Entries
flextype('emitter')->emit('onEntryMove');
if (! $this->has($this->storage['move']['new_id'])) {
return flextype('filesystem')->directory($this->getDirectoryLocation($this->storage['move']['id']))->move($this->getDirectoryLocation($this->storage['move']['new_id']));
return filesystem()->directory($this->getDirectoryLocation($this->storage['move']['id']))->move($this->getDirectoryLocation($this->storage['move']['new_id']));
}
return false;
@@ -234,11 +234,11 @@ class Entries
$entry_file = $this->getFileLocation($this->storage['update']['id']);
if (flextype('filesystem')->file($entry_file)->exists()) {
$body = flextype('filesystem')->file($entry_file)->get();
if (filesystem()->file($entry_file)->exists()) {
$body = filesystem()->file($entry_file)->get();
$entry = flextype('frontmatter')->decode($body);
return (bool) flextype('filesystem')->file($entry_file)->put(flextype('frontmatter')->encode(array_merge($entry, $this->storage['update']['data'])));
return (bool) filesystem()->file($entry_file)->put(flextype('frontmatter')->encode(array_merge($entry, $this->storage['update']['data'])));
}
return false;
@@ -265,15 +265,15 @@ class Entries
// Create entry directory first if it is not exists
$entry_dir = $this->getDirectoryLocation($this->storage['create']['id']);
if (! flextype('filesystem')->directory($entry_dir)->exists() &&
! flextype('filesystem')->directory($entry_dir)->create()) {
if (! filesystem()->directory($entry_dir)->exists() &&
! filesystem()->directory($entry_dir)->create()) {
return false;
}
// Create entry file
$entry_file = $entry_dir . '/entry' . '.' . flextype('registry')->get('flextype.settings.entries.extension');
if (! flextype('filesystem')->file($entry_file)->exists()) {
return (bool) flextype('filesystem')->file($entry_file)->put(flextype('frontmatter')->encode($this->storage['create']['data']));
if (! filesystem()->file($entry_file)->exists()) {
return (bool) filesystem()->file($entry_file)->put(flextype('frontmatter')->encode($this->storage['create']['data']));
}
return false;
@@ -296,7 +296,7 @@ class Entries
// Run event: onEntryDelete
flextype('emitter')->emit('onEntryDelete');
return flextype('filesystem')->directory($this->getDirectoryLocation($this->storage['delete']['id']))->delete();
return filesystem()->directory($this->getDirectoryLocation($this->storage['delete']['id']))->delete();
}
/**
@@ -318,7 +318,7 @@ class Entries
// Run event: onEntryCopy
flextype('emitter')->emit('onEntryCopy');
return flextype('filesystem')->directory($this->getDirectoryLocation($this->storage['copy']['id']))->copy($this->getDirectoryLocation($this->storage['copy']['new_id']));
return filesystem()->directory($this->getDirectoryLocation($this->storage['copy']['id']))->copy($this->getDirectoryLocation($this->storage['copy']['new_id']));
}
/**
@@ -338,7 +338,7 @@ class Entries
// Run event: onEntryHas
flextype('emitter')->emit('onEntryHas');
return flextype('filesystem')->file($this->getFileLocation($this->storage['has']['id']))->exists();
return filesystem()->file($this->getFileLocation($this->storage['has']['id']))->exists();
}
/**
@@ -386,8 +386,8 @@ class Entries
$entry_file = $this->getFileLocation($id);
if (flextype('filesystem')->file($entry_file)->exists()) {
return md5('entry' . $entry_file . (flextype('filesystem')->file($entry_file)->lastModified() ?: ''));
if (filesystem()->file($entry_file)->exists()) {
return md5('entry' . $entry_file . (filesystem()->file($entry_file)->lastModified() ?: ''));
}
return md5('entry' . $entry_file);

View File

@@ -12,7 +12,7 @@ use Atomastic\Strings\Strings;
if (flextype('registry')->get('flextype.settings.entries.fields.created_at.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {
if (flextype('entries')->getStorage('fetch_single.data.created_at') === null) {
flextype('entries')->setStorage('fetch_single.data.created_at', (int) flextype('filesystem')->file(flextype('entries')->getFileLocation(flextype('entries')->getStorage('fetch_single.id')))->lastModified());
flextype('entries')->setStorage('fetch_single.data.created_at', (int) filesystem()->file(flextype('entries')->getFileLocation(flextype('entries')->getStorage('fetch_single.id')))->lastModified());
} else {
flextype('entries')->setStorage('fetch_single.data.created_at', (int) strtotime((string) flextype('entries')->getStorage('fetch_single.data.created_at')));
}

View File

@@ -10,7 +10,7 @@ declare(strict_types=1);
if (flextype('registry')->get('flextype.settings.entries.fields.modified_at.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {
if (flextype('entries')->getStorage('fetch_single.data.modified_at') === null) {
flextype('entries')->setStorage('fetch_single.data.modified_at', (int) flextype('filesystem')->file(flextype('entries')->getFileLocation(flextype('entries')->getStorage('fetch_single.id')))->lastModified());
flextype('entries')->setStorage('fetch_single.data.modified_at', (int) filesystem()->file(flextype('entries')->getFileLocation(flextype('entries')->getStorage('fetch_single.id')))->lastModified());
}
});
}

View File

@@ -58,12 +58,12 @@ class MediaFiles
$upload_folder = PATH['project'] . '/uploads/' . $folder . '/';
$upload_metadata_folder = PATH['project'] . '/uploads/.meta/' . $folder . '/';
if (! flextype('filesystem')->directory($upload_folder)->exists()) {
flextype('filesystem')->directory($upload_folder)->create();
if (! filesystem()->directory($upload_folder)->exists()) {
filesystem()->directory($upload_folder)->create();
}
if (! flextype('filesystem')->directory($upload_metadata_folder)->exists()) {
flextype('filesystem')->directory($upload_metadata_folder)->create();
if (! filesystem()->directory($upload_metadata_folder)->exists()) {
filesystem()->directory($upload_metadata_folder)->create();
}
$accept_file_types = flextype('registry')->get('flextype.settings.media.accept_file_types');
@@ -176,12 +176,12 @@ class MediaFiles
'title' => substr(basename($filename), 0, strrpos(basename($filename), '.')),
'description' => '',
'type' => mime_content_type($filename),
'filesize' => flextype('filesystem')->file($filename)->size(),
'filesize' => filesystem()->file($filename)->size(),
'uploaded_on' => time(),
'exif' => $exif_data,
];
flextype('filesystem')
filesystem()
->file($upload_metadata_folder . basename($filename) . '.yaml')
->put(flextype('yaml')->encode($metadata));
@@ -226,8 +226,8 @@ class MediaFiles
{
$result = [];
if (flextype('filesystem')->file(flextype('media_files_meta')->getFileMetaLocation($path))->exists()) {
$result = flextype('yaml')->decode(flextype('filesystem')->file(flextype('media_files_meta')->getFileMetaLocation($path))->get());
if (filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($path))->exists()) {
$result = flextype('yaml')->decode(filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($path))->get());
$result['filename'] = pathinfo(str_replace('/.meta', '', flextype('media_files_meta')->getFileMetaLocation($path)))['filename'];
$result['basename'] = explode('.', basename(flextype('media_files_meta')->getFileMetaLocation($path)))[0];
@@ -259,11 +259,11 @@ class MediaFiles
{
$result = [];
foreach (flextype('filesystem')->find()->files()->in(flextype('media_folders_meta')->getDirectoryMetaLocation($path)) as $file) {
foreach (filesystem()->find()->files()->in(flextype('media_folders_meta')->getDirectoryMetaLocation($path)) as $file) {
$basename = $file->getBasename('.' . $file->getExtension());
$result[$basename] = flextype('yaml')->decode(flextype('filesystem')->file($file->getPathname())->get());
$result[$basename] = flextype('yaml')->decode(filesystem()->file($file->getPathname())->get());
$result[$basename]['filename'] = pathinfo(str_replace('/.meta', '', flextype('media_files_meta')->getFileMetaLocation($basename)))['filename'];
$result[$basename]['basename'] = explode('.', basename(flextype('media_files_meta')->getFileMetaLocation($basename)))[0];
$result[$basename]['extension'] = ltrim(strstr($basename, '.'), '.');
@@ -294,9 +294,9 @@ class MediaFiles
*/
public function move(string $id, string $new_id): bool
{
if (! flextype('filesystem')->file($this->getFileLocation($new_id))->exists() && ! flextype('filesystem')->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists()) {
return flextype('filesystem')->file($this->getFileLocation($id))->move($this->getFileLocation($new_id)) &&
flextype('filesystem')->file(flextype('media_files_meta')->getFileMetaLocation($id))->move(flextype('media_files_meta')->getFileMetaLocation($new_id));
if (! filesystem()->file($this->getFileLocation($new_id))->exists() && ! filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists()) {
return filesystem()->file($this->getFileLocation($id))->move($this->getFileLocation($new_id)) &&
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->move(flextype('media_files_meta')->getFileMetaLocation($new_id));
}
return false;
@@ -313,8 +313,8 @@ class MediaFiles
*/
public function delete(string $id): bool
{
return flextype('filesystem')->file($this->getFileLocation($id))->delete() &&
flextype('filesystem')->file(flextype('media_files_meta')->getFileMetaLocation($id))->delete();
return filesystem()->file($this->getFileLocation($id))->delete() &&
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->delete();
}
/**
@@ -328,8 +328,8 @@ class MediaFiles
*/
public function has(string $id): bool
{
return flextype('filesystem')->file($this->getFileLocation($id))->exists() &&
flextype('filesystem')->file(flextype('media_files_meta')->getFileMetaLocation($id))->exists();
return filesystem()->file($this->getFileLocation($id))->exists() &&
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->exists();
}
/**
@@ -344,12 +344,12 @@ class MediaFiles
*/
public function copy(string $id, string $new_id): bool
{
if (! flextype('filesystem')->file($this->getFileLocation($new_id))->exists() && ! flextype('filesystem')->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists()) {
flextype('filesystem')->file($this->getFileLocation($id))->copy($this->getFileLocation($new_id));
flextype('filesystem')->file(flextype('media_files_meta')->getFileMetaLocation($id))->copy(flextype('media_files_meta')->getFileMetaLocation($new_id));
if (! filesystem()->file($this->getFileLocation($new_id))->exists() && ! filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists()) {
filesystem()->file($this->getFileLocation($id))->copy($this->getFileLocation($new_id));
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->copy(flextype('media_files_meta')->getFileMetaLocation($new_id));
return flextype('filesystem')->file($this->getFileLocation($new_id))->exists() &&
flextype('filesystem')->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists();
return filesystem()->file($this->getFileLocation($new_id))->exists() &&
filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists();
}
return false;

View File

@@ -26,12 +26,12 @@ class MediaFilesMeta
*/
public function update(string $id, string $field, string $value): bool
{
$file_data = flextype('yaml')->decode(flextype('filesystem')->file($this->getFileMetaLocation($id))->get());
$file_data = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get());
if (arrays($file_data)->has($field)) {
$file_data = arrays($file_data)->set($field, $value);
return (bool) flextype('filesystem')->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray()));
return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray()));
}
return false;
@@ -50,12 +50,12 @@ class MediaFilesMeta
*/
public function add(string $id, string $field, string $value): bool
{
$file_data = flextype('yaml')->decode(flextype('filesystem')->file($this->getFileMetaLocation($id))->get());
$file_data = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get());
if (! arrays($file_data)->has($field)) {
$file_data = arrays($file_data)->set($field, $value);
return (bool) flextype('filesystem')->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray()));
return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray()));
}
return false;
@@ -73,12 +73,12 @@ class MediaFilesMeta
*/
public function delete(string $id, string $field): bool
{
$file_data = flextype('yaml')->decode(flextype('filesystem')->file($this->getFileMetaLocation($id))->get());
$file_data = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get());
if (arrays($file_data)->has($field)) {
$file_data = arrays($file_data)->delete($field);
return (bool) flextype('filesystem')->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray()));
return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray()));
}
return false;

View File

@@ -45,7 +45,7 @@ class MediaFolders
{
$result = [];
if (flextype('filesystem')->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($path))->exists()) {
if (filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($path))->exists()) {
$result['path'] = $path;
$result['full_path'] = str_replace('/.meta', '', flextype('media_folders_meta')->getDirectoryMetaLocation($path));
$result['url'] = 'project/uploads/' . $path;
@@ -73,7 +73,7 @@ class MediaFolders
{
$result = [];
foreach (flextype('filesystem')->find()->directories()->in(flextype('media_folders_meta')->getDirectoryMetaLocation($path)) as $folder) {
foreach (filesystem()->find()->directories()->in(flextype('media_folders_meta')->getDirectoryMetaLocation($path)) as $folder) {
$result[$folder->getFilename()] = $this->fetchSingle($path . '/' . $folder->getFilename());
}
@@ -91,10 +91,10 @@ class MediaFolders
*/
public function create(string $id): bool
{
if (! flextype('filesystem')->directory($this->getDirectoryLocation($id))->exists() &&
! flextype('filesystem')->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->exists()) {
return flextype('filesystem')->directory($this->getDirectoryLocation($id))->create() &&
flextype('filesystem')->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->create();
if (! filesystem()->directory($this->getDirectoryLocation($id))->exists() &&
! filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->exists()) {
return filesystem()->directory($this->getDirectoryLocation($id))->create() &&
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->create();
}
return false;
@@ -112,10 +112,10 @@ class MediaFolders
*/
public function move(string $id, string $new_id): bool
{
if ((flextype('filesystem')->directory($this->getDirectoryLocation($new_id))->exists() === false &&
flextype('filesystem')->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false)) {
return flextype('filesystem')->directory($this->getDirectoryLocation($id))->move($this->getDirectoryLocation($new_id)) &&
flextype('filesystem')->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->move(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id));
if ((filesystem()->directory($this->getDirectoryLocation($new_id))->exists() === false &&
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false)) {
return filesystem()->directory($this->getDirectoryLocation($id))->move($this->getDirectoryLocation($new_id)) &&
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->move(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id));
}
return false;
@@ -133,16 +133,16 @@ class MediaFolders
*/
public function copy(string $id, string $new_id): bool
{
if ((flextype('filesystem')->directory($this->getDirectoryLocation($new_id))->exists() === false &&
flextype('filesystem')->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false)) {
flextype('filesystem')
if ((filesystem()->directory($this->getDirectoryLocation($new_id))->exists() === false &&
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false)) {
filesystem()
->directory($this->getDirectoryLocation($id))
->copy($this->getDirectoryLocation($new_id));
flextype('filesystem')
filesystem()
->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))
->copy(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id));
return flextype('filesystem')->directory($this->getDirectoryLocation($new_id))->exists() &&
flextype('filesystem')->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists();
return filesystem()->directory($this->getDirectoryLocation($new_id))->exists() &&
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists();
}
return false;
@@ -159,8 +159,8 @@ class MediaFolders
*/
public function delete(string $id): bool
{
return flextype('filesystem')->directory($this->getDirectoryLocation($id))->delete() &&
flextype('filesystem')->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->delete();
return filesystem()->directory($this->getDirectoryLocation($id))->delete() &&
filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->delete();
}
/**

View File

@@ -39,7 +39,7 @@ class Plugins
*/
public function __construct()
{
$this->locales = flextype('yaml')->decode(flextype('filesystem')->file(ROOT_DIR . '/src/flextype/locales.yaml')->get());
$this->locales = flextype('yaml')->decode(filesystem()->file(ROOT_DIR . '/src/flextype/locales.yaml')->get());
}
/**
@@ -111,22 +111,22 @@ class Plugins
$project_plugin_settings_file = PATH['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml';
// Create project plugin settings directory
! flextype('filesystem')->directory($project_plugin_settings_dir)->exists() and flextype('filesystem')->directory($project_plugin_settings_dir)->create(0755, true);
! filesystem()->directory($project_plugin_settings_dir)->exists() and filesystem()->directory($project_plugin_settings_dir)->create(0755, true);
// Check if default plugin settings file exists
if (! flextype('filesystem')->file($default_plugin_settings_file)->exists()) {
if (! filesystem()->file($default_plugin_settings_file)->exists()) {
throw new RuntimeException('Load ' . $plugin['dirname'] . ' plugin settings - failed!');
}
// Get default plugin settings content
$default_plugin_settings_file_content = flextype('filesystem')->file($default_plugin_settings_file)->get();
$default_plugin_settings_file_content = filesystem()->file($default_plugin_settings_file)->get();
$default_plugin_settings = flextype('yaml')->decode($default_plugin_settings_file_content);
// Create project plugin settings file
! flextype('filesystem')->file($project_plugin_settings_file)->exists() and flextype('filesystem')->file($project_plugin_settings_file)->put($default_plugin_settings_file_content);
! filesystem()->file($project_plugin_settings_file)->exists() and filesystem()->file($project_plugin_settings_file)->put($default_plugin_settings_file_content);
// Get project plugin settings content
$project_plugin_settings_file_content = flextype('filesystem')->file($project_plugin_settings_file)->get();
$project_plugin_settings_file_content = filesystem()->file($project_plugin_settings_file)->get();
if (trim($project_plugin_settings_file_content) === '') {
$project_plugin_settings = [];
@@ -135,12 +135,12 @@ class Plugins
}
// Check if default plugin manifest file exists
if (! flextype('filesystem')->file($default_plugin_manifest_file)->exists()) {
if (! filesystem()->file($default_plugin_manifest_file)->exists()) {
throw new RuntimeException('Load ' . $plugin['dirname'] . ' plugin manifest - failed!');
}
// Get default plugin manifest content
$default_plugin_manifest_file_content = flextype('filesystem')->file($default_plugin_manifest_file)->get();
$default_plugin_manifest_file_content = filesystem()->file($default_plugin_manifest_file)->get();
$default_plugin_manifest = flextype('yaml')->decode($default_plugin_manifest_file_content);
// Merge plugin settings and manifest data
@@ -194,11 +194,11 @@ class Plugins
foreach ($plugins_list as $plugin) {
$language_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/lang/' . $locale . '.yaml';
if (! flextype('filesystem')->file($language_file)->exists()) {
if (! filesystem()->file($language_file)->exists()) {
continue;
}
if (($content = flextype('filesystem')->file($language_file)->get()) === false) {
if (($content = filesystem()->file($language_file)->get()) === false) {
throw new RuntimeException('Load file: ' . $language_file . ' - failed!');
}
@@ -229,9 +229,9 @@ class Plugins
$default_plugin_manifest_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml';
$project_plugin_settings_file = PATH['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml';
$f1 = flextype('filesystem')->file($default_plugin_settings_file)->exists() ? filemtime($default_plugin_settings_file) : '';
$f2 = flextype('filesystem')->file($default_plugin_manifest_file)->exists() ? filemtime($default_plugin_manifest_file) : '';
$f3 = flextype('filesystem')->file($project_plugin_settings_file)->exists() ? filemtime($project_plugin_settings_file) : '';
$f1 = filesystem()->file($default_plugin_settings_file)->exists() ? filemtime($default_plugin_settings_file) : '';
$f2 = filesystem()->file($default_plugin_manifest_file)->exists() ? filemtime($default_plugin_manifest_file) : '';
$f3 = filesystem()->file($project_plugin_settings_file)->exists() ? filemtime($project_plugin_settings_file) : '';
$_plugins_cache_id .= $f1 . $f2 . $f3;
}
@@ -351,8 +351,8 @@ class Plugins
// Get Plugins List
$plugins_list = [];
if (flextype('filesystem')->directory(PATH['project'] . '/plugins/')->exists()) {
foreach (flextype('filesystem')->find()->in(PATH['project'] . '/plugins/')->directories()->depth(0) as $plugin) {
if (filesystem()->directory(PATH['project'] . '/plugins/')->exists()) {
foreach (filesystem()->find()->in(PATH['project'] . '/plugins/')->directories()->depth(0) as $plugin) {
$plugins_list[$plugin->getBasename()]['dirname'] = $plugin->getBasename();
$plugins_list[$plugin->getBasename()]['pathname'] = $plugin->getPathname();
}

View File

@@ -13,7 +13,6 @@ use Bnf\Slim3Psr15\CallableResolver;
use Cocur\Slugify\Slugify;
use Atomastic\Strings\Strings;
use Atomastic\Session\Session;
use Atomastic\Filesystem\Filesystem;
use Flextype\Foundation\Cors;
use Flextype\Foundation\Entries\Entries;
use Flextype\Foundation\Media\MediaFiles;
@@ -60,13 +59,6 @@ use function in_array;
use function sys_get_temp_dir;
/**
* Add filesystem service to Flextype container
*/
flextype()->container()['filesystem'] = static function () {
return new Filesystem();
};
/**
* Create a standard session hanndler
*/

View File

@@ -13,32 +13,32 @@ afterEach(function (): void {
});
test('test update() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files_meta')->update('foo.txt', 'description', 'Foo description'));
$this->assertEquals('Foo description', flextype('yaml')->decode(flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->get())['description']);
$this->assertEquals('Foo description', flextype('yaml')->decode(filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->get())['description']);
});
test('test add() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files_meta')->add('foo.txt', 'bar', 'Bar'));
$this->assertEquals('Bar', flextype('yaml')->decode(flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->get())['bar']);
$this->assertEquals('Bar', flextype('yaml')->decode(filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->get())['bar']);
});
test('test delete() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files_meta')->delete('foo.txt', 'title'));
$this->assertTrue(empty(flextype('yaml')->decode(flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->get())['bar']));
$this->assertTrue(empty(flextype('yaml')->decode(filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->get())['bar']));
});
test('test getFileMetaLocation() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertStringContainsString('foo.txt.yaml',
flextype('media_files_meta')->getFileMetaLocation('foo.txt'));
});

View File

@@ -13,10 +13,10 @@ afterEach(function (): void {
});
test('test fetch() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
flextype('filesystem')->file(PATH['project'] . '/uploads/bar.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/bar.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Bar', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/bar.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/bar.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Bar', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(count(flextype('media_files')->fetch('foo.txt')) > 0);
$this->assertEquals('Foo', flextype('media_files')->fetch('foo.txt')['title']);
@@ -25,26 +25,26 @@ test('test fetch() method', function () {
});
test('test fetchSingle() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(count(flextype('media_files')->fetchSingle('foo.txt')) > 0);
$this->assertEquals('Foo', flextype('media_files')->fetchSingle('foo.txt')['title']);
});
test('test fetchCollection() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
flextype('filesystem')->file(PATH['project'] . '/uploads/bar.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/bar.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Bar', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/bar.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/bar.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Bar', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(count(flextype('media_files')->fetchCollection('/')) == 2);
$this->assertEquals('Foo', flextype('media_files')->fetchCollection('/')['foo.txt']['title']);
});
test('test move() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files')->move('foo.txt', 'bar.txt'));
$this->assertTrue(flextype('media_files')->move('bar.txt', 'foo.txt'));
@@ -55,8 +55,8 @@ test('test copy() method', function () {
$this->assertTrue(flextype('media_folders')->create('foo'));
$this->assertTrue(flextype('media_folders')->create('bar'));
flextype('filesystem')->file(PATH['project'] . '/uploads/foo/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files')->copy('foo/foo.txt', 'bar/foo.txt'));
$this->assertTrue(flextype('media_files')->copy('foo/foo.txt', 'bar/bar.txt'));
@@ -64,22 +64,22 @@ test('test copy() method', function () {
});
test('test has() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files')->has('foo.txt'));
$this->assertFalse(flextype('media_files')->has('bar.txt'));
});
test('test getFileLocation() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertStringContainsString('foo.txt', flextype('media_files')->getFileLocation('foo.txt'));
});
test('test delete() method', function () {
flextype('filesystem')->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
flextype('filesystem')->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files')->delete('foo.txt'));
$this->assertFalse(flextype('media_files')->delete('foo.txt'));
});