From b78e040577564a0c603918e456fabf6bb38e1799 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 24 Aug 2020 23:27:07 +0300 Subject: [PATCH] feat(core): Improve Flextype Application class #463 --- src/flextype/app/Endpoints/entries.php | 268 ++++++------- src/flextype/app/Endpoints/files.php | 360 +++++++++--------- src/flextype/app/Endpoints/folders.php | 222 +++++------ src/flextype/app/Endpoints/images.php | 34 +- src/flextype/app/Endpoints/registry.php | 36 +- .../app/Foundation/Cache/AcpuCacheAdapter.php | 11 +- .../Foundation/Cache/ArrayCacheAdapter.php | 6 +- src/flextype/app/Foundation/Cache/Cache.php | 42 +- .../Cache/CacheAdapterInterface.php | 2 +- .../Cache/FilesystemCacheAdapter.php | 6 +- .../Cache/MemcachedCacheAdapter.php | 10 +- .../Cache/PhpArrayFileCacheAdapter.php | 6 +- .../Foundation/Cache/PhpFileCacheAdapter.php | 6 +- .../Foundation/Cache/RedisCacheAdapter.php | 14 +- .../Foundation/Cache/SQLite3CacheAdapter.php | 10 +- .../Foundation/Cache/WinCacheCacheAdapter.php | 6 +- .../Cache/ZendDataCacheCacheAdapter.php | 6 +- src/flextype/app/Foundation/Cors.php | 32 +- .../app/Foundation/Entries/Entries.php | 48 +-- .../Entries/Fields/CreatedAtField.php | 18 +- .../Entries/Fields/CreatedByField.php | 10 +- .../app/Foundation/Entries/Fields/IdField.php | 6 +- .../Entries/Fields/ModifiedAtField.php | 6 +- .../Entries/Fields/ParsersField.php | 34 +- .../Entries/Fields/PublishedAtField.php | 18 +- .../Entries/Fields/PublishedByField.php | 10 +- .../Entries/Fields/RoutableField.php | 16 +- .../Foundation/Entries/Fields/SlugField.php | 8 +- .../Foundation/Entries/Fields/UuidField.php | 10 +- .../Entries/Fields/VisibilityField.php | 18 +- .../app/Foundation/Media/MediaFiles.php | 76 ++-- .../app/Foundation/Media/MediaFilesMeta.php | 18 +- .../app/Foundation/Media/MediaFolders.php | 34 +- .../app/Foundation/Media/MediaFoldersMeta.php | 6 +- src/flextype/app/Foundation/Plugins.php | 50 +-- src/flextype/app/Support/Parsers/Markdown.php | 12 +- .../app/Support/Parsers/Shortcode.php | 14 +- .../Parsers/Shortcodes/EntriesShortcode.php | 6 +- .../Parsers/Shortcodes/RawShortcode.php | 6 +- .../Parsers/Shortcodes/RegistryShortcode.php | 6 +- .../Parsers/Shortcodes/UrlShortcode.php | 8 +- .../app/Support/Serializers/Frontmatter.php | 18 +- src/flextype/app/Support/Serializers/Json.php | 12 +- src/flextype/app/Support/Serializers/Yaml.php | 12 +- src/flextype/bootstrap.php | 24 +- src/flextype/dependencies.php | 87 ++--- 46 files changed, 820 insertions(+), 848 deletions(-) diff --git a/src/flextype/app/Endpoints/entries.php b/src/flextype/app/Endpoints/entries.php index e6e13e93..62eddfe6 100644 --- a/src/flextype/app/Endpoints/entries.php +++ b/src/flextype/app/Endpoints/entries.php @@ -38,15 +38,15 @@ function validate_entries_token($token) : bool * Returns: * An array of entry item objects. */ -$flextype->get('/api/entries', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->get('/api/entries', function (Request $request, Response $response) use ($api_errors) { // Get Query Params $query = $request->getQueryParams(); if (! isset($query['id']) || ! isset($query['token'])) { return $response ->withStatus($api_errors['0100']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0100'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0100'])); } // Set variables @@ -54,25 +54,25 @@ $flextype->get('/api/entries', function (Request $request, Response $response) u $token = $query['token']; $filter = $query['filter'] ?? null; - if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) { + if (flextype('registry')->get('flextype.settings.api.entries.enabled')) { // Validate entries token if (validate_entries_token($token)) { $entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml'; // Set entries token file - if ($entries_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($entries_token_file_path))) { + if ($entries_token_file_data = flextype('yaml')->decode(Filesystem::read($entries_token_file_path))) { 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 ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($filter === null) { - $response_data['data'] = $flextype->container('entries')->fetchSingle($id); + $response_data['data'] = flextype('entries')->fetchSingle($id); } else { - $response_data['data'] = $flextype->container('entries')->fetchCollection($id, $filter); + $response_data['data'] = flextype('entries')->fetchCollection($id, $filter); } // Set response code @@ -83,38 +83,38 @@ $flextype->get('/api/entries', function (Request $request, Response $response) u } // Update calls counter - Filesystem::write($entries_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); + Filesystem::write($entries_token_file_path, flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0102']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0102']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0102']['http_status_code'])); } return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -131,15 +131,15 @@ $flextype->get('/api/entries', function (Request $request, Response $response) u * Returns: * Returns the entry item object for the entry item that was just created. */ -$flextype->post('/api/entries', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->post('/api/entries', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['id']) || ! isset($post_data['data'])) { return $response ->withStatus($api_errors['0101']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0101']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0101']['http_status_code'])); } // Set variables @@ -148,36 +148,36 @@ $flextype->post('/api/entries', function (Request $request, Response $response) $id = $post_data['id']; $data = $post_data['data']; - if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) { + if (flextype('registry')->get('flextype.settings.api.entries.enabled')) { // Validate entries and access token if (validate_entries_token($token) && validate_access_token($access_token)) { $entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set entries and access token file - if (($entries_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($entries_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($entries_token_file_data = flextype('yaml')->decode(Filesystem::read($entries_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($access_token_file_path)))) { 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 ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Create entry - $create_entry = $flextype->container('entries')->create($id, $data); + $create_entry = flextype('entries')->create($id, $data); if ($create_entry) { - $response_data['data'] = $flextype->container('entries')->fetch($id); + $response_data['data'] = flextype('entries')->fetch($id); } else { $response_data['data'] = []; } @@ -186,39 +186,39 @@ $flextype->post('/api/entries', function (Request $request, Response $response) $response_code = $create_entry ? 200 : 404; // Update calls counter - Filesystem::write($entries_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); + Filesystem::write($entries_token_file_path, flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0102']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0102']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0102']['http_status_code'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -235,15 +235,15 @@ $flextype->post('/api/entries', function (Request $request, Response $response) * Returns: * Returns the entry item object for the entry item that was just updated. */ -$flextype->patch('/api/entries', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->patch('/api/entries', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['id']) || ! isset($post_data['data'])) { return $response ->withStatus($api_errors['0101']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0101']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0101']['http_status_code'])); } // Set variables @@ -252,36 +252,36 @@ $flextype->patch('/api/entries', function (Request $request, Response $response) $id = $post_data['id']; $data = $post_data['data']; - if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) { + if (flextype('registry')->get('flextype.settings.api.entries.enabled')) { // Validate entries and access token if (validate_entries_token($token) && validate_access_token($access_token)) { $entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set entries and access token file - if (($entries_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($entries_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($entries_token_file_data = flextype('yaml')->decode(Filesystem::read($entries_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($access_token_file_path)))) { 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 ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Update entry - $update_entry = $flextype->container('entries')->update($id, $data); + $update_entry = flextype('entries')->update($id, $data); if ($update_entry) { - $response_data['data'] = $flextype->container('entries')->fetch($id); + $response_data['data'] = flextype('entries')->fetch($id); } else { $response_data['data'] = []; } @@ -290,39 +290,39 @@ $flextype->patch('/api/entries', function (Request $request, Response $response) $response_code = $update_entry ? 200 : 404; // Update calls counter - Filesystem::write($entries_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); + Filesystem::write($entries_token_file_path, flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0102']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0102']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0102']['http_status_code'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -339,15 +339,15 @@ $flextype->patch('/api/entries', function (Request $request, Response $response) * Returns: * Returns the entry item object for the entry item that was just renamed. */ -$flextype->put('/api/entries', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->put('/api/entries', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['id']) || ! isset($post_data['new_id'])) { return $response ->withStatus($api_errors['0101']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0101']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0101']['http_status_code'])); } // Set variables @@ -356,37 +356,37 @@ $flextype->put('/api/entries', function (Request $request, Response $response) u $id = $post_data['id']; $new_id = $post_data['new_id']; - if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) { + if (flextype('registry')->get('flextype.settings.api.entries.enabled')) { // Validate entries and access token if (validate_entries_token($token) && validate_access_token($access_token)) { $entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set entries and access token file - if (($entries_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($entries_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($entries_token_file_data = flextype('yaml')->decode(Filesystem::read($entries_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($access_token_file_path)))) { 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 ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Rename entry - $rename_entry = $flextype->container('entries')->rename($id, $new_id); + $rename_entry = flextype('entries')->rename($id, $new_id); // Get entry data if ($rename_entry) { - $response_data['data'] = $flextype->container('entries')->fetch($new_id); + $response_data['data'] = flextype('entries')->fetch($new_id); } else { $response_data['data'] = []; } @@ -395,39 +395,39 @@ $flextype->put('/api/entries', function (Request $request, Response $response) u $response_code = $rename_entry ? 200 : 404; // Update calls counter - Filesystem::write($entries_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); + Filesystem::write($entries_token_file_path, flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0102']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0102']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0102']['http_status_code'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -444,15 +444,15 @@ $flextype->put('/api/entries', function (Request $request, Response $response) u * Returns: * Returns the entry item object for the entry item that was just copied. */ -$flextype->put('/api/entries/copy', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->put('/api/entries/copy', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['id']) || ! isset($post_data['new_id'])) { return $response ->withStatus($api_errors['0101']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0101']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0101']['http_status_code'])); } // Set variables @@ -461,37 +461,37 @@ $flextype->put('/api/entries/copy', function (Request $request, Response $respon $id = $post_data['id']; $new_id = $post_data['new_id']; - if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) { + if (flextype('registry')->get('flextype.settings.api.entries.enabled')) { // Validate entries and access token if (validate_entries_token($token) && validate_access_token($access_token)) { $entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set entries and access token file - if (($entries_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($entries_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($entries_token_file_data = flextype('yaml')->decode(Filesystem::read($entries_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($access_token_file_path)))) { 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 ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Copy entry - $copy_entry = $flextype->container('entries')->copy($id, $new_id, true); + $copy_entry = flextype('entries')->copy($id, $new_id, true); // Get entry data if ($copy_entry === null) { - $response_data['data'] = $flextype->container('entries')->fetch($new_id); + $response_data['data'] = flextype('entries')->fetch($new_id); } else { $response_data['data'] = []; } @@ -500,39 +500,39 @@ $flextype->put('/api/entries/copy', function (Request $request, Response $respon $response_code = $copy_entry === null ? 200 : 404; // Update calls counter - Filesystem::write($entries_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); + Filesystem::write($entries_token_file_path, flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0102']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0102']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0102']['http_status_code'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -548,15 +548,15 @@ $flextype->put('/api/entries/copy', function (Request $request, Response $respon * Returns: * Returns an empty body with HTTP status 204 */ -$flextype->delete('/api/entries', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->delete('/api/entries', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['id'])) { return $response ->withStatus($api_errors['0101']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0101']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0101']['http_status_code'])); } // Set variables @@ -564,69 +564,69 @@ $flextype->delete('/api/entries', function (Request $request, Response $response $access_token = $post_data['access_token']; $id = $post_data['id']; - if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) { + if (flextype('registry')->get('flextype.settings.api.entries.enabled')) { // Validate entries and access token if (validate_entries_token($token) && validate_access_token($access_token)) { $entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set entries and access token file - if (($entries_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($entries_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($entries_token_file_data = flextype('yaml')->decode(Filesystem::read($entries_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($access_token_file_path)))) { 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 ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Delete entry - $delete_entry = $flextype->container('entries')->delete($id); + $delete_entry = flextype('entries')->delete($id); // Set response code $response_code = $delete_entry ? 204 : 404; // Update calls counter - Filesystem::write($entries_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); + Filesystem::write($entries_token_file_path, flextype('yaml')->encode(array_replace_recursive($entries_token_file_data, ['calls' => $entries_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0102']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0102']['http_status_code'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0102']['http_status_code'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($delete_entry)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($delete_entry)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); diff --git a/src/flextype/app/Endpoints/files.php b/src/flextype/app/Endpoints/files.php index d97aa2bd..7e5282b0 100644 --- a/src/flextype/app/Endpoints/files.php +++ b/src/flextype/app/Endpoints/files.php @@ -37,33 +37,33 @@ function validate_files_token($token) : bool * Returns: * An array of file item objects. */ -$flextype->get('/api/files', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->get('/api/files', function (Request $request, Response $response) use ($api_errors) { // Get Query Params $query = $request->getQueryParams(); if (! isset($query['path']) || ! isset($query['token'])) { return $response->withStatus($api_errors['0500']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0500'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0500'])); } // Set variables $path = $query['path']; $token = $query['token']; - if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) { + if (flextype('registry')->get('flextype.settings.api.files.enabled')) { // Validate delivery token if (validate_files_token($token)) { $files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml'; // Set delivery token file - if ($files_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($files_token_file_path))) { + if ($files_token_file_data = flextype('yaml')->decode(Filesystem::read($files_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'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Create files array @@ -71,9 +71,9 @@ $flextype->get('/api/files', function (Request $request, Response $response) use // Get list if file or files for specific folder if (is_dir(PATH['project'] . '/uploads/' . $path)) { - $files = $flextype->container('media_files')->fetchCollection($path); + $files = flextype('media_files')->fetchCollection($path); } else { - $files = $flextype->container('media_files')->fetchSingle($path); + $files = flextype('media_files')->fetchSingle($path); } // Write response data @@ -84,39 +84,39 @@ $flextype->get('/api/files', function (Request $request, Response $response) use $response_code = count($response_data['data']) > 0 ? 200 : 404; // Update calls counter - Filesystem::write($files_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); + Filesystem::write($files_token_file_path, flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0502']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0502'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0502'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -133,14 +133,14 @@ $flextype->get('/api/files', function (Request $request, Response $response) use * Returns: * Returns the file object for the file that was just uploaded. */ -$flextype->post('/api/files', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->post('/api/files', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['folder']) || ! isset($_FILES['file'])) { return $response->withStatus($api_errors['0501']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Set variables @@ -149,77 +149,77 @@ $flextype->post('/api/files', function (Request $request, Response $response) us $folder = $post_data['folder']; $file = $_FILES['file']; - if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) { + if (flextype('registry')->get('flextype.settings.api.files.enabled')) { // Validate files and access token if (validate_files_token($token) && validate_access_token($access_token)) { $files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($files_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($files_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($files_token_file_data = flextype('yaml')->decode(Filesystem::read($files_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($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'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Create file - $create_file = $flextype->container('media_files')->upload($file, $folder); + $create_file = flextype('media_files')->upload($file, $folder); $response_data['data'] = []; if ($create_file) { - $response_data['data'] = $flextype->container('media_files')->fetch($folder . '/' . basename($create_file)); + $response_data['data'] = flextype('media_files')->fetch($folder . '/' . basename($create_file)); } // Set response code $response_code = Filesystem::has($create_file) ? 200 : 404; // Update calls counter - Filesystem::write($files_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); + Filesystem::write($files_token_file_path, flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0502']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0502'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0502'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); @@ -237,14 +237,14 @@ $flextype->post('/api/files', function (Request $request, Response $response) us * Returns: * Returns the file object for the file that was just created. */ -$flextype->put('/api/files', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->put('/api/files', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path']) || ! isset($post_data['new_path'])) { return $response->withStatus($api_errors['0501']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Set variables @@ -253,77 +253,77 @@ $flextype->put('/api/files', function (Request $request, Response $response) use $path = $post_data['path']; $new_path = $post_data['new_path']; - if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) { + if (flextype('registry')->get('flextype.settings.api.files.enabled')) { // Validate files and access token if (validate_files_token($token) && validate_access_token($access_token)) { $files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($files_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($files_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($files_token_file_data = flextype('yaml')->decode(Filesystem::read($files_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($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'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Rename file - $rename_file = $flextype->container('media_files')->rename($path, $new_path); + $rename_file = flextype('media_files')->rename($path, $new_path); $response_data['data'] = []; if ($rename_file) { - $response_data['data'] = $flextype->container('media_files')->fetch($new_path); + $response_data['data'] = flextype('media_files')->fetch($new_path); } // Set response code $response_code = $rename_file === true ? 200 : 404; // Update calls counter - Filesystem::write($files_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); + Filesystem::write($files_token_file_path, flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0502']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0502'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0502'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -340,14 +340,14 @@ $flextype->put('/api/files', function (Request $request, Response $response) use * Returns: * Returns the file object for the file that was just created. */ -$flextype->put('/api/files/copy', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->put('/api/files/copy', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path']) || ! isset($post_data['new_path'])) { return $response->withStatus($api_errors['0501']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Set variables @@ -356,77 +356,77 @@ $flextype->put('/api/files/copy', function (Request $request, Response $response $path = $post_data['path']; $new_path = $post_data['new_path']; - if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) { + if (flextype('registry')->get('flextype.settings.api.files.enabled')) { // Validate files and access token if (validate_files_token($token) && validate_access_token($access_token)) { $files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($files_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($files_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($files_token_file_data = flextype('yaml')->decode(Filesystem::read($files_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($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'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Copy file - $copy_file = $flextype->container('media_files')->copy($path, $new_path); + $copy_file = flextype('media_files')->copy($path, $new_path); $response_data['data'] = []; if ($copy_file) { - $response_data['data'] = $flextype->container('media_files')->fetch($new_path); + $response_data['data'] = flextype('media_files')->fetch($new_path); } // Set response code $response_code = $copy_file === true ? 200 : 404; // Update calls counter - Filesystem::write($files_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); + Filesystem::write($files_token_file_path, flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0502']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0502'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0502'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -442,14 +442,14 @@ $flextype->put('/api/files/copy', function (Request $request, Response $response * Returns: * Returns an empty body with HTTP status 204 */ -$flextype->delete('/api/files', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->delete('/api/files', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['path']) || ! isset($post_data['access_token']) || ! isset($post_data['path'])) { return $response->withStatus($api_errors['0501']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Set variables @@ -457,71 +457,71 @@ $flextype->delete('/api/files', function (Request $request, Response $response) $access_token = $post_data['access_token']; $path = $post_data['path']; - if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) { + if (flextype('registry')->get('flextype.settings.api.files.enabled')) { // Validate files and access token if (validate_files_token($token) && validate_access_token($access_token)) { $files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($files_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($files_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($files_token_file_data = flextype('yaml')->decode(Filesystem::read($files_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($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'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Delete file - $delete_file = $flextype->container('media_files')->delete($path); + $delete_file = flextype('media_files')->delete($path); // Set response code $response_code = $delete_file ? 204 : 404; // Update calls counter - Filesystem::write($files_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); + Filesystem::write($files_token_file_path, flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0502']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0502'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0502'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($delete_file)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($delete_file)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -539,14 +539,14 @@ $flextype->delete('/api/files', function (Request $request, Response $response) * Returns: * Returns the file object for the file that was just updated. */ -$flextype->patch('/api/files/meta', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->patch('/api/files/meta', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path']) || ! isset($post_data['field']) || ! isset($post_data['value'])) { return $response->withStatus($api_errors['0501']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Set variables @@ -556,77 +556,77 @@ $flextype->patch('/api/files/meta', function (Request $request, Response $respon $field = $post_data['field']; $value = $post_data['value']; - if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) { + if (flextype('registry')->get('flextype.settings.api.files.enabled')) { // Validate files and access token if (validate_files_token($token) && validate_access_token($access_token)) { $files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($files_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($files_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($files_token_file_data = flextype('yaml')->decode(Filesystem::read($files_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($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'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Update file meta - $update_file_meta = $flextype->container('media_files_meta')->update($path, $field, $value); + $update_file_meta = flextype('media_files_meta')->update($path, $field, $value); $response_data['data'] = []; if ($update_file_meta) { - $response_data['data'] = $flextype->container('media_files')->fetch($path); + $response_data['data'] = flextype('media_files')->fetch($path); } // Set response code $response_code = $update_file_meta ? 200 : 404; // Update calls counter - Filesystem::write($files_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); + Filesystem::write($files_token_file_path, flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0502']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0502'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0502'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -644,14 +644,14 @@ $flextype->patch('/api/files/meta', function (Request $request, Response $respon * Returns: * Returns the file object for the file that was just created. */ -$flextype->post('/api/files/meta', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->post('/api/files/meta', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path']) || ! isset($post_data['field']) || ! isset($post_data['value'])) { return $response->withStatus($api_errors['0501']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Set variables @@ -661,77 +661,77 @@ $flextype->post('/api/files/meta', function (Request $request, Response $respons $field = $post_data['field']; $value = $post_data['value']; - if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) { + if (flextype('registry')->get('flextype.settings.api.files.enabled')) { // Validate files and access token if (validate_files_token($token) && validate_access_token($access_token)) { $files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($files_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($files_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($files_token_file_data = flextype('yaml')->decode(Filesystem::read($files_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($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'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Add file meta - $add_file_meta = $flextype->container('media_files_meta')->add($path, $field, $value); + $add_file_meta = flextype('media_files_meta')->add($path, $field, $value); $response_data['data'] = []; if ($add_file_meta) { - $response_data['data'] = $flextype->container('media_files')->fetch($path); + $response_data['data'] = flextype('media_files')->fetch($path); } // Set response code $response_code = $add_file_meta ? 200 : 404; // Update calls counter - Filesystem::write($files_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); + Filesystem::write($files_token_file_path, flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0502']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0502'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0502'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); @@ -749,14 +749,14 @@ $flextype->post('/api/files/meta', function (Request $request, Response $respons * Returns: * Returns the file object for the file that was just created. */ -$flextype->delete('/api/files/meta', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->delete('/api/files/meta', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path']) || ! isset($post_data['field'])) { return $response->withStatus($api_errors['0501']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Set variables @@ -765,75 +765,75 @@ $flextype->delete('/api/files/meta', function (Request $request, Response $respo $path = $post_data['path']; $field = $post_data['field']; - if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) { + if (flextype('registry')->get('flextype.settings.api.files.enabled')) { // Validate files and access token if (validate_files_token($token) && validate_access_token($access_token)) { $files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($files_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($files_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($files_token_file_data = flextype('yaml')->decode(Filesystem::read($files_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($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'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Delete file meta - $delete_file_meta = $flextype->container('media_files_meta')->delete($path, $field); + $delete_file_meta = flextype('media_files_meta')->delete($path, $field); $response_data['data'] = []; if ($delete_file_meta) { - $response_data['data'] = $flextype->container('media_files')->fetch($path); + $response_data['data'] = flextype('media_files')->fetch($path); } // Set response code $response_code = $delete_file_meta ? 200 : 404; // Update calls counter - Filesystem::write($files_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); + Filesystem::write($files_token_file_path, flextype('yaml')->encode(array_replace_recursive($files_token_file_data, ['calls' => $files_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0502']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0502'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0502'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); diff --git a/src/flextype/app/Endpoints/folders.php b/src/flextype/app/Endpoints/folders.php index 68be3aa0..c2561378 100644 --- a/src/flextype/app/Endpoints/folders.php +++ b/src/flextype/app/Endpoints/folders.php @@ -36,14 +36,14 @@ function validate_folders_token($token) : bool * Returns: * An array of folder(s) item objects. */ -$flextype->get('/api/folders', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->get('/api/folders', function (Request $request, Response $response) use ($api_errors) { // Get Query Params $query = $request->getQueryParams(); if (! isset($query['path']) || ! isset($query['token'])) { return $response->withStatus($api_errors['0600']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0600'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0600'])); } // Set variables @@ -60,18 +60,18 @@ $flextype->get('/api/folders', function (Request $request, Response $response) u $collection = false; } - if ($flextype->container('registry')->get('flextype.settings.api.folders.enabled')) { + if (flextype('registry')->get('flextype.settings.api.folders.enabled')) { // Validate delivery token if (validate_folders_token($token)) { $folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml'; // Set delivery token file - if ($folders_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($folders_token_file_path))) { + if ($folders_token_file_data = flextype('yaml')->decode(Filesystem::read($folders_token_file_path))) { 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']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Create folders array @@ -79,9 +79,9 @@ $flextype->get('/api/folders', function (Request $request, Response $response) u // Get list if folder or fodlers for specific folder if ($collection) { - $folders = $flextype->container('media_folders')->fetchCollection($path); + $folders = flextype('media_folders')->fetchCollection($path); } else { - $folders = $flextype->container('media_folders')->fetchSingle($path); + $folders = flextype('media_folders')->fetchSingle($path); } // Write response data @@ -92,39 +92,39 @@ $flextype->get('/api/folders', function (Request $request, Response $response) u $response_code = count($response_data['data']) > 0 ? 200 : 404; // Update calls counter - Filesystem::write($folders_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]))); + Filesystem::write($folders_token_file_path, flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0602']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0602'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0602'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); @@ -141,14 +141,14 @@ $flextype->get('/api/folders', function (Request $request, Response $response) u * Returns: * Returns the folder object for the folder that was just created. */ -$flextype->post('/api/folders', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->post('/api/folders', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path'])) { return $response->withStatus($api_errors['0601']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0601'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0601'])); } // Set variables @@ -156,75 +156,75 @@ $flextype->post('/api/folders', function (Request $request, Response $response) $access_token = $post_data['access_token']; $path = $post_data['path']; - if ($flextype->container('registry')->get('flextype.settings.api.folders.enabled')) { + if (flextype('registry')->get('flextype.settings.api.folders.enabled')) { // Validate files and access token if (validate_folders_token($token) && validate_access_token($access_token)) { $folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($folders_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($folders_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($folders_token_file_data = flextype('yaml')->decode(Filesystem::read($folders_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($access_token_file_path)))) { 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']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response->withStatus($api_errors['0501']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Create folder - $create_folder = $flextype->container('media_folders')->create($path); + $create_folder = flextype('media_folders')->create($path); $response_data = []; if ($create_folder) { - $response_data['data'] = $flextype->container('media_folders')->fetch($path); + $response_data['data'] = flextype('media_folders')->fetch($path); } // Set response code $response_code = $create_folder ? 200 : 404; // Update calls counter - Filesystem::write($folders_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]))); + Filesystem::write($folders_token_file_path, flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0602']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0602'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0602'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -241,14 +241,14 @@ $flextype->post('/api/folders', function (Request $request, Response $response) * Returns: * Returns the folders object for the folders that was just copied. */ -$flextype->put('/api/folders/copy', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->put('/api/folders/copy', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path']) || ! isset($post_data['new_path'])) { return $response->withStatus($api_errors['0601']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0601'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0601'])); } // Set variables @@ -257,36 +257,36 @@ $flextype->put('/api/folders/copy', function (Request $request, Response $respon $path = $post_data['path']; $new_path = $post_data['new_path']; - if ($flextype->container('registry')->get('flextype.settings.api.folders.enabled')) { + if (flextype('registry')->get('flextype.settings.api.folders.enabled')) { // Validate files and access token if (validate_folders_token($token) && validate_access_token($access_token)) { $folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($folders_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($folders_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($folders_token_file_data = flextype('yaml')->decode(Filesystem::read($folders_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($access_token_file_path)))) { 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']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0601'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0601'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response->withStatus($api_errors['0601']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0601'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0601'])); } // Copy folder - $copy_folder = $flextype->container('media_folders')->copy($path, $new_path); + $copy_folder = flextype('media_folders')->copy($path, $new_path); $response_data = []; if ($copy_folder) { - $response_data['data'] = $flextype->container('media_folders')->fetch($new_path); + $response_data['data'] = flextype('media_folders')->fetch($new_path); } else { $response_data['data'] = $copy_folder; } @@ -295,39 +295,39 @@ $flextype->put('/api/folders/copy', function (Request $request, Response $respon $response_code = $copy_folder ? 200 : 404; // Update calls counter - Filesystem::write($folders_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]))); + Filesystem::write($folders_token_file_path, flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0602']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0602'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0602'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -344,14 +344,14 @@ $flextype->put('/api/folders/copy', function (Request $request, Response $respon * Returns: * Returns the folders object for the folders that was just renamed. */ -$flextype->put('/api/folders', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->put('/api/folders', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path']) || ! isset($post_data['new_path'])) { return $response->withStatus($api_errors['0601']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0601'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0601'])); } // Set variables @@ -360,75 +360,75 @@ $flextype->put('/api/folders', function (Request $request, Response $response) u $path = $post_data['path']; $new_path = $post_data['new_path']; - if ($flextype->container('registry')->get('flextype.settings.api.folders.enabled')) { + if (flextype('registry')->get('flextype.settings.api.folders.enabled')) { // Validate files and access token if (validate_folders_token($token) && validate_access_token($access_token)) { $folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($folders_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($folders_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($folders_token_file_data = flextype('yaml')->decode(Filesystem::read($folders_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($access_token_file_path)))) { 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']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response->withStatus($api_errors['0501']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Rename folder - $rename_folder = $flextype->container('media_folders')->rename($path, $new_path); + $rename_folder = flextype('media_folders')->rename($path, $new_path); $response_data = []; if ($rename_folder) { - $response_data['data'] = $flextype->container('media_folders')->fetch($new_path); + $response_data['data'] = flextype('media_folders')->fetch($new_path); } // Set response code $response_code = $rename_folder ? 200 : 404; // Update calls counter - Filesystem::write($folders_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]))); + Filesystem::write($folders_token_file_path, flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0602']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0602'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0602'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($response_data)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($response_data)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); /** @@ -444,14 +444,14 @@ $flextype->put('/api/folders', function (Request $request, Response $response) u * Returns: * Returns an empty body with HTTP status 204 */ -$flextype->delete('/api/folders', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->delete('/api/folders', function (Request $request, Response $response) use ($api_errors) { // Get Post Data $post_data = $request->getParsedBody(); if (! isset($post_data['token']) || ! isset($post_data['access_token']) || ! isset($post_data['path'])) { return $response->withStatus($api_errors['0601']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0601'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0601'])); } // Set variables @@ -459,67 +459,67 @@ $flextype->delete('/api/folders', function (Request $request, Response $response $access_token = $post_data['access_token']; $path = $post_data['path']; - if ($flextype->container('registry')->get('flextype.settings.api.folders.enabled')) { + if (flextype('registry')->get('flextype.settings.api.folders.enabled')) { // Validate files and access token if (validate_folders_token($token) && validate_access_token($access_token)) { $folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml'; $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set files and access token file - if (($folders_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($folders_token_file_path))) && - ($access_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($access_token_file_path)))) { + if (($folders_token_file_data = flextype('yaml')->decode(Filesystem::read($folders_token_file_path))) && + ($access_token_file_data = flextype('yaml')->decode(Filesystem::read($access_token_file_path)))) { 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']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { return $response->withStatus($api_errors['0501']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0501'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0501'])); } // Delete folder - $delete_folder = $flextype->container('media_folders')->delete($path); + $delete_folder = flextype('media_folders')->delete($path); // Set response code $response_code = $delete_folder ? 204 : 404; // Update calls counter - Filesystem::write($folders_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]))); + Filesystem::write($folders_token_file_path, flextype('yaml')->encode(array_replace_recursive($folders_token_file_data, ['calls' => $folders_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0602']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0602'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0602'])); } // Return response return $response ->withStatus($response_code) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($delete_folder)); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($delete_folder)); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); diff --git a/src/flextype/app/Endpoints/images.php b/src/flextype/app/Endpoints/images.php index c2270384..91a93c2b 100644 --- a/src/flextype/app/Endpoints/images.php +++ b/src/flextype/app/Endpoints/images.php @@ -36,60 +36,60 @@ function validate_images_token($token) : bool * Returns: * Image file */ -$flextype->get('/api/images/{path:.+}', function (Request $request, Response $response, $args) use ($flextype, $api_errors) { +flextype()->get('/api/images/{path:.+}', function (Request $request, Response $response, $args) use ($api_errors) { // Get Query Params $query = $request->getQueryParams(); if (! isset($query['token'])) { return $response->withStatus($api_errors['0400']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0400'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0400'])); } // Set variables $token = $query['token']; - if ($flextype->container('registry')->get('flextype.settings.api.images.enabled')) { + if (flextype('registry')->get('flextype.settings.api.images.enabled')) { // Validate delivery image token if (validate_images_token($token)) { $delivery_images_token_file_path = PATH['project'] . '/tokens/images/' . $token . '/token.yaml'; // Set delivery token file - if ($delivery_images_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($delivery_images_token_file_path))) { + if ($delivery_images_token_file_data = flextype('yaml')->decode(Filesystem::read($delivery_images_token_file_path))) { 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']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Update calls counter - Filesystem::write($delivery_images_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($delivery_images_token_file_data, ['calls' => $delivery_images_token_file_data['calls'] + 1]))); + Filesystem::write($delivery_images_token_file_path, flextype('yaml')->encode(array_replace_recursive($delivery_images_token_file_data, ['calls' => $delivery_images_token_file_data['calls'] + 1]))); if (Filesystem::has(PATH['project'] . '/uploads/entries/' . $args['path'])) { - return $flextype->container('images')->getImageResponse($args['path'], $_GET); + return flextype('images')->getImageResponse($args['path'], $_GET); } return $response ->withStatus($api_errors['0402']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0402'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0402'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); diff --git a/src/flextype/app/Endpoints/registry.php b/src/flextype/app/Endpoints/registry.php index 996ceabd..9d44cd9f 100644 --- a/src/flextype/app/Endpoints/registry.php +++ b/src/flextype/app/Endpoints/registry.php @@ -34,38 +34,38 @@ function validate_registry_token($token) : bool * Returns: * An array of registry item objects. */ -$flextype->get('/api/registry', function (Request $request, Response $response) use ($flextype, $api_errors) { +flextype()->get('/api/registry', function (Request $request, Response $response) use ($api_errors) { // Get Query Params $query = $request->getQueryParams(); if (! isset($query['id']) || ! isset($query['token'])) { return $response->withStatus($api_errors['0300']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0300'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0300'])); } // Set variables $id = $query['id']; $token = $query['token']; - if ($flextype->container('registry')->get('flextype.settings.api.registry.enabled')) { + if (flextype('registry')->get('flextype.settings.api.registry.enabled')) { // Validate token if (validate_registry_token($token)) { $registry_token_file_path = PATH['project'] . '/tokens/registry/' . $token . '/token.yaml'; // Set token file - if ($registry_token_file_data = $flextype->container('yaml')->decode(Filesystem::read($registry_token_file_path))) { + if ($registry_token_file_data = flextype('yaml')->decode(Filesystem::read($registry_token_file_path))) { 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']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } // Fetch registry - if ($flextype->container('registry')->has($id)) { + if (flextype('registry')->has($id)) { $response_data['data']['key'] = $id; - $response_data['data']['value'] = $flextype->container('registry')->get($id); + $response_data['data']['value'] = flextype('registry')->get($id); // Set response code $response_code = 200; @@ -75,14 +75,14 @@ $flextype->get('/api/registry', function (Request $request, Response $response) } // Update calls counter - Filesystem::write($registry_token_file_path, $flextype->container('yaml')->encode(array_replace_recursive($registry_token_file_data, ['calls' => $registry_token_file_data['calls'] + 1]))); + Filesystem::write($registry_token_file_path, flextype('yaml')->encode(array_replace_recursive($registry_token_file_data, ['calls' => $registry_token_file_data['calls'] + 1]))); if ($response_code === 404) { // Return response return $response ->withStatus($api_errors['0302']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0302'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0302'])); } // Return response @@ -92,18 +92,18 @@ $flextype->get('/api/registry', function (Request $request, Response $response) return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); } return $response ->withStatus($api_errors['0003']['http_status_code']) - ->withHeader('Content-Type', 'application/json;charset=' . $flextype->container('registry')->get('flextype.settings.charset')) - ->write($flextype->container('json')->encode($api_errors['0003'])); + ->withHeader('Content-Type', 'application/json;charset=' . flextype('registry')->get('flextype.settings.charset')) + ->write(flextype('json')->encode($api_errors['0003'])); }); diff --git a/src/flextype/app/Foundation/Cache/AcpuCacheAdapter.php b/src/flextype/app/Foundation/Cache/AcpuCacheAdapter.php index 78c6c3eb..5badae9a 100644 --- a/src/flextype/app/Foundation/Cache/AcpuCacheAdapter.php +++ b/src/flextype/app/Foundation/Cache/AcpuCacheAdapter.php @@ -8,16 +8,9 @@ use Doctrine\Common\Cache\AcpuCache; class AcpuCacheAdapter implements CacheAdapterInterface { - /** - * Flextype Application - * - * @access private - */ - protected $flextype; - - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } public function getDriver() : object diff --git a/src/flextype/app/Foundation/Cache/ArrayCacheAdapter.php b/src/flextype/app/Foundation/Cache/ArrayCacheAdapter.php index 84184c37..5c00b9d1 100644 --- a/src/flextype/app/Foundation/Cache/ArrayCacheAdapter.php +++ b/src/flextype/app/Foundation/Cache/ArrayCacheAdapter.php @@ -13,11 +13,11 @@ class ArrayCacheAdapter implements CacheAdapterInterface * * @access private */ - protected $flextype; - public function __construct($flextype) + + public function __construct() { - $this->flextype = $flextype; + } public function getDriver() : object diff --git a/src/flextype/app/Foundation/Cache/Cache.php b/src/flextype/app/Foundation/Cache/Cache.php index 98748f74..231e9397 100755 --- a/src/flextype/app/Foundation/Cache/Cache.php +++ b/src/flextype/app/Foundation/Cache/Cache.php @@ -22,7 +22,7 @@ class Cache /** * Flextype Application */ - protected $flextype; + /** * Unique cache key @@ -57,9 +57,9 @@ class Cache * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + // Create Cache Directory ! Filesystem::has(PATH['cache']) and Filesystem::createDir(PATH['cache']); @@ -68,8 +68,8 @@ class Cache $this->now = time(); // Create cache key to allow invalidate all cache on configuration changes. - $cache_prefix = ($this->flextype->container('registry')->get('flextype.settings.cache.prefix') ?? 'flextype'); - $cache_unique_string = md5(PATH['project'] . $this->flextype->container('registry')->get('flextype.manifest.version')); + $cache_prefix = (flextype('registry')->get('flextype.settings.cache.prefix') ?? 'flextype'); + $cache_unique_string = md5(PATH['project'] . flextype('registry')->get('flextype.manifest.version')); $this->key = $cache_prefix . $cache_unique_string; // Get Cache Driver @@ -86,7 +86,7 @@ class Cache */ public function getCacheDriver() : object { - return $this->flextype->container('cache_adapter')->getDriver(); + return flextype('cache_adapter')->getDriver(); } /** @@ -120,7 +120,7 @@ class Cache */ public function fetch(string $id) { - if ($this->flextype->container('registry')->get('flextype.settings.cache.enabled')) { + if (flextype('registry')->get('flextype.settings.cache.enabled')) { return $this->driver->fetch($id); } @@ -136,7 +136,7 @@ class Cache */ public function fetchMultiple(array $keys) : array { - if ($this->flextype->container('registry')->get('flextype.settings.cache.enabled')) { + if (flextype('registry')->get('flextype.settings.cache.enabled')) { return $this->driver->fetchMultiple($keys); } @@ -152,7 +152,7 @@ class Cache */ public function contains(string $id) : bool { - if ($this->flextype->container('registry')->get('flextype.settings.cache.enabled')) { + if (flextype('registry')->get('flextype.settings.cache.enabled')) { return $this->driver->contains($id); } @@ -174,7 +174,7 @@ class Cache */ public function save(string $id, $data, ?int $lifetime = null) : bool { - if (! $this->flextype->container('registry')->get('flextype.settings.cache.enabled')) { + if (! flextype('registry')->get('flextype.settings.cache.enabled')) { return false; } @@ -196,7 +196,7 @@ class Cache */ public function saveMultiple(array $keysAndValues, int $lifetime = 0) : bool { - if (! $this->flextype->container('registry')->get('flextype.settings.cache.enabled')) { + if (! flextype('registry')->get('flextype.settings.cache.enabled')) { return false; } @@ -212,7 +212,7 @@ class Cache */ public function delete(string $id) : bool { - if (! $this->flextype->container('registry')->get('flextype.settings.cache.enabled')) { + if (! flextype('registry')->get('flextype.settings.cache.enabled')) { return false; } @@ -228,7 +228,7 @@ class Cache */ public function deleteMultiple(array $keys) : bool { - if (! $this->flextype->container('registry')->get('flextype.settings.cache.enabled')) { + if (! flextype('registry')->get('flextype.settings.cache.enabled')) { return false; } @@ -242,7 +242,7 @@ class Cache */ public function getStats() : ?array { - if (! $this->flextype->container('registry')->get('flextype.settings.cache.enabled')) { + if (! flextype('registry')->get('flextype.settings.cache.enabled')) { return false; } @@ -254,7 +254,7 @@ class Cache */ public function deleteAll() : bool { - if (! $this->flextype->container('registry')->get('flextype.settings.cache.enabled')) { + if (! flextype('registry')->get('flextype.settings.cache.enabled')) { return false; } @@ -268,7 +268,7 @@ class Cache */ public function flushAll() : bool { - if (! $this->flextype->container('registry')->get('flextype.settings.cache.enabled')) { + if (! flextype('registry')->get('flextype.settings.cache.enabled')) { return false; } @@ -307,7 +307,7 @@ class Cache public function getLifetime() { if ($this->lifetime === null) { - $this->lifetime = $this->flextype->container('registry')->get('flextype.settings.cache.lifetime') ?: 604800; + $this->lifetime = flextype('registry')->get('flextype.settings.cache.lifetime') ?: 604800; } return $this->lifetime; @@ -323,7 +323,7 @@ class Cache public function purge(string $directory) : void { // Run event: onCacheBeforePurge - $this->flextype->container('emitter')->emit('onCacheBeforePurge'); + flextype('emitter')->emit('onCacheBeforePurge'); // Remove specific cache directory Filesystem::deleteDir(PATH['cache'] . '/' . $directory); @@ -342,7 +342,7 @@ class Cache error_reporting($errorReporting); // Run event: onCacheAfterPurge - $this->flextype->container('emitter')->emit('onCacheAfterPurge'); + flextype('emitter')->emit('onCacheAfterPurge'); } /** @@ -353,7 +353,7 @@ class Cache public function purgeAll() : void { // Run event: onCacheAfterPurgeAll - $this->flextype->container('emitter')->emit('onCacheAfterPurgeAll'); + flextype('emitter')->emit('onCacheAfterPurgeAll'); // Remove cache directory Filesystem::deleteDir(PATH['cache']); @@ -372,6 +372,6 @@ class Cache error_reporting($errorReporting); // Run event: onCacheAfterPurgeAll - $this->flextype->container('emitter')->emit('onCacheAfterPurgeAll'); + flextype('emitter')->emit('onCacheAfterPurgeAll'); } } diff --git a/src/flextype/app/Foundation/Cache/CacheAdapterInterface.php b/src/flextype/app/Foundation/Cache/CacheAdapterInterface.php index 79738892..999cb2a7 100644 --- a/src/flextype/app/Foundation/Cache/CacheAdapterInterface.php +++ b/src/flextype/app/Foundation/Cache/CacheAdapterInterface.php @@ -11,7 +11,7 @@ interface CacheAdapterInterface * * @return void */ - public function __construct($flextype); + public function __construct(); /** * Returns the cache driver object diff --git a/src/flextype/app/Foundation/Cache/FilesystemCacheAdapter.php b/src/flextype/app/Foundation/Cache/FilesystemCacheAdapter.php index c6e52eae..aba86a32 100644 --- a/src/flextype/app/Foundation/Cache/FilesystemCacheAdapter.php +++ b/src/flextype/app/Foundation/Cache/FilesystemCacheAdapter.php @@ -14,11 +14,11 @@ class FilesystemCacheAdapter implements CacheAdapterInterface * * @access private */ - protected $flextype; - public function __construct($flextype) + + public function __construct() { - $this->flextype = $flextype; + } public function getDriver() : object diff --git a/src/flextype/app/Foundation/Cache/MemcachedCacheAdapter.php b/src/flextype/app/Foundation/Cache/MemcachedCacheAdapter.php index ce583bae..695c5f64 100644 --- a/src/flextype/app/Foundation/Cache/MemcachedCacheAdapter.php +++ b/src/flextype/app/Foundation/Cache/MemcachedCacheAdapter.php @@ -14,19 +14,19 @@ class MemcachedCacheAdapter implements CacheAdapterInterface * * @access private */ - protected $flextype; - public function __construct($flextype) + + public function __construct() { - $this->flextype = $flextype; + } public function getDriver() : object { $memcached = new Memecached(); $memcached->addServer( - $this->flextype->container('registry')->get('flextype.settings.cache.memcached.server', 'localhost'), - $this->flextype->container('registry')->get('flextype.settings.cache.memcache.port', 11211) + flextype('registry')->get('flextype.settings.cache.memcached.server', 'localhost'), + flextype('registry')->get('flextype.settings.cache.memcache.port', 11211) ); $driver = new MemcachedCache(); diff --git a/src/flextype/app/Foundation/Cache/PhpArrayFileCacheAdapter.php b/src/flextype/app/Foundation/Cache/PhpArrayFileCacheAdapter.php index e39569b2..38ab6b68 100644 --- a/src/flextype/app/Foundation/Cache/PhpArrayFileCacheAdapter.php +++ b/src/flextype/app/Foundation/Cache/PhpArrayFileCacheAdapter.php @@ -13,11 +13,11 @@ class PhpArrayFileCacheAdapter implements CacheAdapterInterface * * @access private */ - protected $flextype; - public function __construct($flextype) + + public function __construct() { - $this->flextype = $flextype; + } public function getDriver() : object diff --git a/src/flextype/app/Foundation/Cache/PhpFileCacheAdapter.php b/src/flextype/app/Foundation/Cache/PhpFileCacheAdapter.php index 3818a037..f4fcf109 100644 --- a/src/flextype/app/Foundation/Cache/PhpFileCacheAdapter.php +++ b/src/flextype/app/Foundation/Cache/PhpFileCacheAdapter.php @@ -14,11 +14,11 @@ class PhpFileCacheAdapter implements CacheAdapterInterface * * @access private */ - protected $flextype; - public function __construct($flextype) + + public function __construct() { - $this->flextype = $flextype; + } public function getDriver() : object diff --git a/src/flextype/app/Foundation/Cache/RedisCacheAdapter.php b/src/flextype/app/Foundation/Cache/RedisCacheAdapter.php index 369c9908..0734a387 100644 --- a/src/flextype/app/Foundation/Cache/RedisCacheAdapter.php +++ b/src/flextype/app/Foundation/Cache/RedisCacheAdapter.php @@ -15,25 +15,25 @@ class RedisCacheAdapter implements CacheAdapterInterface * * @access private */ - protected $flextype; - public function __construct($flextype) + + public function __construct() { - $this->flextype = $flextype; + } public function getDriver() : object { $redis = new Redis(); - $socket = $this->flextype->container('registry')->get('flextype.settings.cache.redis.socket', false); - $password = $this->flextype->container('registry')->get('flextype.settings.cache.redis.password', false); + $socket = flextype('registry')->get('flextype.settings.cache.redis.socket', false); + $password = flextype('registry')->get('flextype.settings.cache.redis.password', false); if ($socket) { $redis->connect($socket); } else { $redis->connect( - $this->flextype->container('registry')->get('flextype.settings.cache.redis.server', 'localhost'), - $this->flextype->container('registry')->get('flextype.settings.cache.redis.port', 6379) + flextype('registry')->get('flextype.settings.cache.redis.server', 'localhost'), + flextype('registry')->get('flextype.settings.cache.redis.port', 6379) ); } diff --git a/src/flextype/app/Foundation/Cache/SQLite3CacheAdapter.php b/src/flextype/app/Foundation/Cache/SQLite3CacheAdapter.php index 172dc3da..d83ac9c3 100644 --- a/src/flextype/app/Foundation/Cache/SQLite3CacheAdapter.php +++ b/src/flextype/app/Foundation/Cache/SQLite3CacheAdapter.php @@ -15,11 +15,11 @@ class SQLite3CacheAdapter implements CacheAdapterInterface * * @access private */ - protected $flextype; - public function __construct($flextype) + + public function __construct() { - $this->flextype = $flextype; + } public function getDriver() : object @@ -30,8 +30,8 @@ class SQLite3CacheAdapter implements CacheAdapterInterface Filesystem::createDir($cache_directory); } - $db = new SQLite3($cache_directory . $this->flextype->container('registry')->get('flextype.settings.cache.sqlite3.database', 'flextype') . '.db'); + $db = new SQLite3($cache_directory . flextype('registry')->get('flextype.settings.cache.sqlite3.database', 'flextype') . '.db'); - return new SQLite3Cache($db, $this->flextype->container('registry')->get('flextype.settings.cache.sqlite3.table', 'flextype')); + return new SQLite3Cache($db, flextype('registry')->get('flextype.settings.cache.sqlite3.table', 'flextype')); } } diff --git a/src/flextype/app/Foundation/Cache/WinCacheCacheAdapter.php b/src/flextype/app/Foundation/Cache/WinCacheCacheAdapter.php index c9cfd31d..51cf6892 100644 --- a/src/flextype/app/Foundation/Cache/WinCacheCacheAdapter.php +++ b/src/flextype/app/Foundation/Cache/WinCacheCacheAdapter.php @@ -13,11 +13,11 @@ class WinCacheCacheAdapter implements CacheAdapterInterface * * @access private */ - protected $flextype; - public function __construct($flextype) + + public function __construct() { - $this->flextype = $flextype; + } public function getDriver() : object diff --git a/src/flextype/app/Foundation/Cache/ZendDataCacheCacheAdapter.php b/src/flextype/app/Foundation/Cache/ZendDataCacheCacheAdapter.php index 5bcdf7dc..25cfabcf 100644 --- a/src/flextype/app/Foundation/Cache/ZendDataCacheCacheAdapter.php +++ b/src/flextype/app/Foundation/Cache/ZendDataCacheCacheAdapter.php @@ -13,11 +13,11 @@ class ZendDataCacheCacheAdapter implements CacheAdapterInterface * * @access private */ - protected $flextype; - public function __construct($flextype) + + public function __construct() { - $this->flextype = $flextype; + } public function getDriver() : object diff --git a/src/flextype/app/Foundation/Cors.php b/src/flextype/app/Foundation/Cors.php index 91543755..666b8d2c 100644 --- a/src/flextype/app/Foundation/Cors.php +++ b/src/flextype/app/Foundation/Cors.php @@ -14,44 +14,28 @@ use function implode; class Cors { - /** - * Flextype Application - */ - protected $flextype; - - /** - * __construct - */ - public function __construct($flextype) - { - $this->flextype = $flextype; - } - /** * Init CORS */ public function init() : void { - - $flextype = $this->flextype; - - if (! $flextype->container('registry')->get('flextype.settings.cors.enabled')) { + if (! flextype('registry')->get('flextype.settings.cors.enabled')) { return; } - $flextype->options('/{routes:.+}', function ($request, $response) { + flextype()->options('/{routes:.+}', function ($request, $response) { return $response; }); - $flextype->add(function ($req, $res, $next) use ($flextype) { + flextype()->add(function ($req, $res, $next) { $response = $next($req, $res); // Set variables - $origin = $flextype->container('registry')->get('flextype.settings.cors.origin'); - $headers = count($flextype->container('registry')->get('flextype.settings.cors.headers')) ? implode(', ', $flextype->container('registry')->get('flextype.settings.cors.headers')) : ''; - $methods = count($flextype->container('registry')->get('flextype.settings.cors.methods')) ? implode(', ', $flextype->container('registry')->get('flextype.settings.cors.methods')) : ''; - $expose = count($flextype->container('registry')->get('flextype.settings.cors.expose')) ? implode(', ', $flextype->container('registry')->get('flextype.settings.cors.expose')) : ''; - $credentials = $flextype->container('registry')->get('flextype.settings.cors.credentials') ? true : false; + $origin = flextype('registry')->get('flextype.settings.cors.origin'); + $headers = count(flextype('registry')->get('flextype.settings.cors.headers')) ? implode(', ', flextype('registry')->get('flextype.settings.cors.headers')) : ''; + $methods = count(flextype('registry')->get('flextype.settings.cors.methods')) ? implode(', ', flextype('registry')->get('flextype.settings.cors.methods')) : ''; + $expose = count(flextype('registry')->get('flextype.settings.cors.expose')) ? implode(', ', flextype('registry')->get('flextype.settings.cors.expose')) : ''; + $credentials = flextype('registry')->get('flextype.settings.cors.credentials') ? true : false; return $response ->withHeader('Access-Control-Allow-Origin', $origin) diff --git a/src/flextype/app/Foundation/Entries/Entries.php b/src/flextype/app/Foundation/Entries/Entries.php index 95c23193..044b25fc 100755 --- a/src/flextype/app/Foundation/Entries/Entries.php +++ b/src/flextype/app/Foundation/Entries/Entries.php @@ -73,16 +73,16 @@ class Entries /** * Flextype Application */ - protected $flextype; + /** * Constructor * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -123,12 +123,12 @@ class Entries $entry_cache_id = $this->getCacheID($this->entry_id); // Try to get current requested entry from cache - if ($this->flextype->container('cache')->contains($entry_cache_id)) { + if (flextype('cache')->contains($entry_cache_id)) { // Fetch entry from cache - $this->entry = $this->flextype->container('cache')->fetch($entry_cache_id); + $this->entry = flextype('cache')->fetch($entry_cache_id); // Run event: onEntryAfterCacheInitialized - $this->flextype->container('emitter')->emit('onEntryAfterCacheInitialized'); + flextype('emitter')->emit('onEntryAfterCacheInitialized'); // Return entry from cache return $this->entry; @@ -146,18 +146,18 @@ class Entries } // Decode entry file content - $this->entry = $this->flextype->container('frontmatter')->decode($entry_file_content); + $this->entry = flextype('frontmatter')->decode($entry_file_content); // Run event: onEntryAfterInitialized - $this->flextype->container('emitter')->emit('onEntryAfterInitialized'); + flextype('emitter')->emit('onEntryAfterInitialized'); // Set cache state - $cache = $this->flextype->container('entries')->entry['cache']['enabled'] ?? - $this->flextype->container('registry')->get('flextype.settings.cache.enabled'); + $cache = flextype('entries')->entry['cache']['enabled'] ?? + flextype('registry')->get('flextype.settings.cache.enabled'); // Save entry data to cache if ($cache) { - $this->flextype->container('cache')->save($entry_cache_id, $this->entry); + flextype('cache')->save($entry_cache_id, $this->entry); } // Return entry data @@ -195,7 +195,7 @@ class Entries // Fetch single entry. if (count($entries_list) > 0) { foreach ($entries_list as $current_entry) { - if ($current_entry->getType() !== 'file' || $current_entry->getFilename() !== 'entry' . '.' . $this->flextype->container('registry')->get('flextype.settings.entries.extension')) { + if ($current_entry->getType() !== 'file' || $current_entry->getFilename() !== 'entry' . '.' . flextype('registry')->get('flextype.settings.entries.extension')) { continue; } @@ -207,7 +207,7 @@ class Entries $this->entries = collect_filter($this->entries, $filter); // Run event: onEntriesAfterInitialized - $this->flextype->container('emitter')->emit('onEntriesAfterInitialized'); + flextype('emitter')->emit('onEntriesAfterInitialized'); } // Return entries array @@ -228,7 +228,7 @@ class Entries { if (! Filesystem::has($this->getDirLocation($new_id))) { // Run event: onEntryRename - $this->flextype->container('emitter')->emit('onEntryRename'); + flextype('emitter')->emit('onEntryRename'); return rename($this->getDirLocation($id), $this->getDirLocation($new_id)); } @@ -252,15 +252,15 @@ class Entries if (Filesystem::has($entry_file)) { $body = Filesystem::read($entry_file); - $entry = $this->flextype->container('frontmatter')->decode($body); + $entry = flextype('frontmatter')->decode($body); // Store data in the entry_update_data $this->entry_update_data = $data; // Run event: onEntryUpdate - $this->flextype->container('emitter')->emit('onEntryUpdate'); + flextype('emitter')->emit('onEntryUpdate'); - return Filesystem::write($entry_file, $this->flextype->container('frontmatter')->encode(array_merge($entry, $this->entry_update_data))); + return Filesystem::write($entry_file, flextype('frontmatter')->encode(array_merge($entry, $this->entry_update_data))); } return false; @@ -284,15 +284,15 @@ class Entries // Try to create directory for new entry if (Filesystem::createDir($entry_dir)) { // Check if new entry file exists - if (! Filesystem::has($entry_file = $entry_dir . '/entry' . '.' . $this->flextype->container('registry')->get('flextype.settings.entries.extension'))) { + if (! Filesystem::has($entry_file = $entry_dir . '/entry' . '.' . flextype('registry')->get('flextype.settings.entries.extension'))) { // Store data in the entry_create_data $this->entry_create_data = $data; // Run event: onEntryCreate - $this->flextype->container('emitter')->emit('onEntryCreate'); + flextype('emitter')->emit('onEntryCreate'); // Create a new entry! - return Filesystem::write($entry_file, $this->flextype->container('frontmatter')->encode($this->entry_create_data)); + return Filesystem::write($entry_file, flextype('frontmatter')->encode($this->entry_create_data)); } return false; @@ -314,7 +314,7 @@ class Entries public function delete(string $id) : bool { // Run event: onEntryDelete - $this->flextype->container('emitter')->emit('onEntryDelete'); + flextype('emmiter')->emit('onEntryDelete'); return Filesystem::deleteDir($this->getDirLocation($id)); } @@ -333,7 +333,7 @@ class Entries public function copy(string $id, string $new_id, bool $deep = false) : ?bool { // Run event: onEntryRename - $this->flextype->container('emitter')->emit('onEntryCopy'); + flextype('emitter')->emit('onEntryCopy'); return Filesystem::copy($this->getDirLocation($id), $this->getDirLocation($new_id), $deep); } @@ -363,7 +363,7 @@ class Entries */ public function getFileLocation(string $id) : string { - return PATH['project'] . '/entries/' . $id . '/entry' . '.' . $this->flextype->container('registry')->get('flextype.settings.entries.extension'); + return PATH['project'] . '/entries/' . $id . '/entry' . '.' . flextype('registry')->get('flextype.settings.entries.extension'); } /** @@ -391,7 +391,7 @@ class Entries */ public function getCacheID(string $id) : string { - if ($this->flextype->container('registry')->get('flextype.settings.cache.enabled') === false) { + if (flextype('registry')->get('flextype.settings.cache.enabled') === false) { return ''; } diff --git a/src/flextype/app/Foundation/Entries/Fields/CreatedAtField.php b/src/flextype/app/Foundation/Entries/Fields/CreatedAtField.php index eae5a0f0..0087fea4 100644 --- a/src/flextype/app/Foundation/Entries/Fields/CreatedAtField.php +++ b/src/flextype/app/Foundation/Entries/Fields/CreatedAtField.php @@ -9,18 +9,18 @@ declare(strict_types=1); use Flextype\Component\Filesystem\Filesystem; -if ($flextype->container('registry')->get('flextype.settings.entries.fields.created_at.enabled')) { - $flextype->container('emitter')->addListener('onEntryAfterInitialized', static function () use ($flextype) : void { - $flextype->container('entries')->entry['created_at'] = isset($flextype->container('entries')->entry['created_at']) ? - (int) strtotime($flextype->container('entries')->entry['created_at']) : - (int) Filesystem::getTimestamp($flextype->container('entries')->getFileLocation($flextype->container('entries')->entry_id)); +if (flextype('registry')->get('flextype.settings.entries.fields.created_at.enabled')) { + flextype('emitter')->addListener('onEntryAfterInitialized', static function () : void { + flextype('entries')->entry['created_at'] = isset(flextype('entries')->entry['created_at']) ? + (int) strtotime(flextype('entries')->entry['created_at']) : + (int) Filesystem::getTimestamp(flextype('entries')->getFileLocation(flextype('entries')->entry_id)); }); - $flextype->container('emitter')->addListener('onEntryCreate', static function () use ($flextype) : void { - if (isset($flextype->container('entries')->entry_create_data['created_at'])) { - $flextype->container('entries')->entry_create_data['created_at'] = $flextype->container('entries')->entry_create_data['created_at']; + flextype('emitter')->addListener('onEntryCreate', static function () : void { + if (isset(flextype('entries')->entry_create_data['created_at'])) { + flextype('entries')->entry_create_data['created_at'] = flextype('entries')->entry_create_data['created_at']; } else { - $flextype->container('entries')->entry_create_data['created_at'] = date($flextype->container('registry')->get('flextype.settings.date_format'), time()); + flextype('entries')->entry_create_data['created_at'] = date(flextype('registry')->get('flextype.settings.date_format'), time()); } }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/CreatedByField.php b/src/flextype/app/Foundation/Entries/Fields/CreatedByField.php index 6503290b..5939a992 100644 --- a/src/flextype/app/Foundation/Entries/Fields/CreatedByField.php +++ b/src/flextype/app/Foundation/Entries/Fields/CreatedByField.php @@ -7,12 +7,12 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if ($flextype->container('registry')->get('flextype.settings.entries.fields.created_by.enabled')) { - $flextype->container('emitter')->addListener('onEntryCreate', static function () use ($flextype) : void { - if (isset($flextype->container('entries')->entry_create_data['created_by'])) { - $flextype->container('entries')->entry_create_data['created_by'] = $flextype->container('entries')->entry_create_data['created_by']; +if (flextype('registry')->get('flextype.settings.entries.fields.created_by.enabled')) { + flextype('emitter')->addListener('onEntryCreate', static function () : void { + if (isset(flextype('entries')->entry_create_data['created_by'])) { + flextype('entries')->entry_create_data['created_by'] = flextype('entries')->entry_create_data['created_by']; } else { - $flextype->container('entries')->entry_create_data['created_by'] = ''; + flextype('entries')->entry_create_data['created_by'] = ''; } }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/IdField.php b/src/flextype/app/Foundation/Entries/Fields/IdField.php index 68cbeec5..6f034419 100644 --- a/src/flextype/app/Foundation/Entries/Fields/IdField.php +++ b/src/flextype/app/Foundation/Entries/Fields/IdField.php @@ -7,8 +7,8 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if ($flextype->container('registry')->get('flextype.settings.entries.fields.id.enabled')) { - $flextype->container('emitter')->addListener('onEntryAfterInitialized', static function () use ($flextype) : void { - $flextype->container('entries')->entry['id'] = isset($flextype->container('entries')->entry['id']) ? (string) $flextype->container('entries')->entry['id'] : (string) ltrim(rtrim($flextype->container('entries')->entry_id, '/'), '/'); +if (flextype('registry')->get('flextype.settings.entries.fields.id.enabled')) { + flextype('emitter')->addListener('onEntryAfterInitialized', static function () : void { + flextype('entries')->entry['id'] = isset(flextype('entries')->entry['id']) ? (string) flextype('entries')->entry['id'] : (string) ltrim(rtrim(flextype('entries')->entry_id, '/'), '/'); }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/ModifiedAtField.php b/src/flextype/app/Foundation/Entries/Fields/ModifiedAtField.php index 7761b4e3..13b1b9f2 100644 --- a/src/flextype/app/Foundation/Entries/Fields/ModifiedAtField.php +++ b/src/flextype/app/Foundation/Entries/Fields/ModifiedAtField.php @@ -9,8 +9,8 @@ declare(strict_types=1); use Flextype\Component\Filesystem\Filesystem; -if ($flextype->container('registry')->get('flextype.settings.entries.fields.modified_at.enabled')) { - $flextype->container('emitter')->addListener('onEntryAfterInitialized', static function () use ($flextype) : void { - $flextype->container('entries')->entry['modified_at'] = (int) Filesystem::getTimestamp($flextype->container('entries')->getFileLocation($flextype->container('entries')->entry_id)); +if (flextype('registry')->get('flextype.settings.entries.fields.modified_at.enabled')) { + flextype('emitter')->addListener('onEntryAfterInitialized', static function () : void { + flextype('entries')->entry['modified_at'] = (int) Filesystem::getTimestamp(flextype('entries')->getFileLocation(flextype('entries')->entry_id)); }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/ParsersField.php b/src/flextype/app/Foundation/Entries/Fields/ParsersField.php index f8507189..87a04922 100644 --- a/src/flextype/app/Foundation/Entries/Fields/ParsersField.php +++ b/src/flextype/app/Foundation/Entries/Fields/ParsersField.php @@ -9,46 +9,46 @@ declare(strict_types=1); use Flextype\Component\Arrays\Arrays; -if ($flextype->container('registry')->get('flextype.settings.entries.fields.parsers.enabled')) { - $flextype->container('emitter')->addListener('onEntryAfterInitialized', static function () use ($flextype) : void { - processParsersField($flextype); +if (flextype('registry')->get('flextype.settings.entries.fields.parsers.enabled')) { + flextype('emitter')->addListener('onEntryAfterInitialized', static function () : void { + processParsersField(); }); } -function processParsersField($flextype) : void +function processParsersField() : void { - $cache = $flextype->container('entries')->entry['cache']['enabled'] ?? - $flextype->container('registry')->get('flextype.settings.cache.enabled'); + $cache = flextype('entries')->entry['cache']['enabled'] ?? + flextype('registry')->get('flextype.settings.cache.enabled'); - if (! isset($flextype->container('entries')->entry['parsers'])) { + if (! isset(flextype('entries')->entry['parsers'])) { return; } - foreach ($flextype->container('entries')->entry['parsers'] as $parser_name => $parser_data) { + foreach (flextype('entries')->entry['parsers'] as $parser_name => $parser_data) { if (! in_array($parser_name, ['markdown', 'shortcode'])) { continue; } - if (! isset($flextype->container('entries')->entry['parsers'][$parser_name]['enabled']) || $flextype->container('entries')->entry['parsers'][$parser_name]['enabled'] !== true) { + if (! isset(flextype('entries')->entry['parsers'][$parser_name]['enabled']) || flextype('entries')->entry['parsers'][$parser_name]['enabled'] !== true) { continue; } - if (! isset($flextype->container('entries')->entry['parsers'][$parser_name]['fields'])) { + if (! isset(flextype('entries')->entry['parsers'][$parser_name]['fields'])) { continue; } - if (! is_array($flextype->container('entries')->entry['parsers'][$parser_name]['fields'])) { + if (! is_array(flextype('entries')->entry['parsers'][$parser_name]['fields'])) { continue; } - foreach ($flextype->container('entries')->entry['parsers'][$parser_name]['fields'] as $field) { - if (in_array($field, $flextype->container('registry')->get('flextype.settings.entries.fields'))) { + foreach (flextype('entries')->entry['parsers'][$parser_name]['fields'] as $field) { + if (in_array($field, flextype('registry')->get('flextype.settings.entries.fields'))) { continue; } if ($parser_name === 'markdown') { - if (Arrays::has($flextype->container('entries')->entry, $field)) { - Arrays::set($flextype->container('entries')->entry, $field, $flextype->markdown->parse(Arrays::get($flextype->container('entries')->entry, $field), $cache)); + if (Arrays::has(flextype('entries')->entry, $field)) { + Arrays::set(flextype('entries')->entry, $field, flextype('markdown')->parse(Arrays::get(flextype('entries')->entry, $field), $cache)); } } @@ -56,11 +56,11 @@ function processParsersField($flextype) : void continue; } - if (! Arrays::has($flextype->container('entries')->entry, $field)) { + if (! Arrays::has(flextype('entries')->entry, $field)) { continue; } - Arrays::set($flextype->container('entries')->entry, $field, $flextype->shortcode->parse(Arrays::get($flextype->container('entries')->entry, $field), $cache)); + Arrays::set(flextype('entries')->entry, $field, flextype('shortcode')->parse(Arrays::get(flextype('entries')->entry, $field), $cache)); } } } diff --git a/src/flextype/app/Foundation/Entries/Fields/PublishedAtField.php b/src/flextype/app/Foundation/Entries/Fields/PublishedAtField.php index 04a8bae0..ac465c2c 100644 --- a/src/flextype/app/Foundation/Entries/Fields/PublishedAtField.php +++ b/src/flextype/app/Foundation/Entries/Fields/PublishedAtField.php @@ -9,18 +9,18 @@ declare(strict_types=1); use Flextype\Component\Filesystem\Filesystem; -if ($flextype->container('registry')->get('flextype.settings.entries.fields.published_at.enabled')) { - $flextype->container('emitter')->addListener('onEntryAfterInitialized', static function () use ($flextype) : void { - $flextype->container('entries')->entry['published_at'] = isset($flextype->container('entries')->entry['published_at']) ? - (int) strtotime($flextype->container('entries')->entry['published_at']) : - (int) Filesystem::getTimestamp($flextype->container('entries')->getFileLocation($flextype->container('entries')->entry_id)); +if (flextype('registry')->get('flextype.settings.entries.fields.published_at.enabled')) { + flextype('emitter')->addListener('onEntryAfterInitialized', static function () : void { + flextype('entries')->entry['published_at'] = isset(flextype('entries')->entry['published_at']) ? + (int) strtotime(flextype('entries')->entry['published_at']) : + (int) Filesystem::getTimestamp(flextype('entries')->getFileLocation(flextype('entries')->entry_id)); }); - $flextype->container('emitter')->addListener('onEntryCreate', static function () use ($flextype) : void { - if (isset($flextype->container('entries')->entry_create_data['published_at'])) { - $flextype->container('entries')->entry_create_data['published_at'] = $flextype->container('entries')->entry_create_data['published_at']; + flextype('emitter')->addListener('onEntryCreate', static function () : void { + if (isset(flextype('entries')->entry_create_data['published_at'])) { + flextype('entries')->entry_create_data['published_at'] = flextype('entries')->entry_create_data['published_at']; } else { - $flextype->container('entries')->entry_create_data['published_at'] = date($flextype->container('registry')->get('flextype.settings.date_format'), time()); + flextype('entries')->entry_create_data['published_at'] = date(flextype('registry')->get('flextype.settings.date_format'), time()); } }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/PublishedByField.php b/src/flextype/app/Foundation/Entries/Fields/PublishedByField.php index da5496f0..526d95ad 100644 --- a/src/flextype/app/Foundation/Entries/Fields/PublishedByField.php +++ b/src/flextype/app/Foundation/Entries/Fields/PublishedByField.php @@ -7,12 +7,12 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if ($flextype->container('registry')->get('flextype.settings.entries.fields.published_by.enabled')) { - $flextype->container('emitter')->addListener('onEntryCreate', static function () use ($flextype) : void { - if (isset($flextype->container('entries')->entry_create_data['published_by'])) { - $flextype->container('entries')->entry_create_data['published_by'] = $flextype->container('entries')->entry_create_data['published_by']; +if (flextype('registry')->get('flextype.settings.entries.fields.published_by.enabled')) { + flextype('emitter')->addListener('onEntryCreate', static function () : void { + if (isset(flextype('entries')->entry_create_data['published_by'])) { + flextype('entries')->entry_create_data['published_by'] = flextype('entries')->entry_create_data['published_by']; } else { - $flextype->container('entries')->entry_create_data['published_by'] = ''; + flextype('entries')->entry_create_data['published_by'] = ''; } }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/RoutableField.php b/src/flextype/app/Foundation/Entries/Fields/RoutableField.php index 98eb9963..f85f3125 100644 --- a/src/flextype/app/Foundation/Entries/Fields/RoutableField.php +++ b/src/flextype/app/Foundation/Entries/Fields/RoutableField.php @@ -8,18 +8,18 @@ declare(strict_types=1); */ -if ($flextype->container('registry')->get('flextype.settings.entries.fields.routable.enabled')) { - $flextype->container('emitter')->addListener('onEntryAfterInitialized', static function () use ($flextype) : void { - $flextype->container('entries')->entry['routable'] = isset($flextype->container('entries')->entry['routable']) ? - (bool) $flextype->container('entries')->entry['routable'] : +if (flextype('registry')->get('flextype.settings.entries.fields.routable.enabled')) { + flextype('emitter')->addListener('onEntryAfterInitialized', static function () : void { + flextype('entries')->entry['routable'] = isset(flextype('entries')->entry['routable']) ? + (bool) flextype('entries')->entry['routable'] : true; }); - $flextype->container('emitter')->addListener('onEntryCreate', static function () use ($flextype) : void { - if (isset($flextype->container('entries')->entry_create_data['routable']) && is_bool($flextype->container('entries')->entry_create_data['routable'])) { - $flextype->container('entries')->entry_create_data['routable'] = $flextype->container('entries')->entry_create_data['routable']; + flextype('emitter')->addListener('onEntryCreate', static function () : void { + if (isset(flextype('entries')->entry_create_data['routable']) && is_bool(flextype('entries')->entry_create_data['routable'])) { + flextype('entries')->entry_create_data['routable'] = flextype('entries')->entry_create_data['routable']; } else { - $flextype->container('entries')->entry_create_data['routable'] = true; + flextype('entries')->entry_create_data['routable'] = true; } }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/SlugField.php b/src/flextype/app/Foundation/Entries/Fields/SlugField.php index 094729cd..345153a0 100644 --- a/src/flextype/app/Foundation/Entries/Fields/SlugField.php +++ b/src/flextype/app/Foundation/Entries/Fields/SlugField.php @@ -7,9 +7,9 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if ($flextype->container('registry')->get('flextype.settings.entries.fields.slug.enabled')) { - $flextype->container('emitter')->addListener('onEntryAfterInitialized', static function () use ($flextype) : void { - $parts = explode('/', ltrim(rtrim($flextype->container('entries')->entry_id, '/'), '/')); - $flextype->container('entries')->entry['slug'] = isset($flextype->container('entries')->entry['slug']) ? (string) $flextype->container('entries')->entry['slug'] : (string) end($parts); +if (flextype('registry')->get('flextype.settings.entries.fields.slug.enabled')) { + flextype('emitter')->addListener('onEntryAfterInitialized', static function () : void { + $parts = explode('/', ltrim(rtrim(flextype('entries')->entry_id, '/'), '/')); + flextype('entries')->entry['slug'] = isset(flextype('entries')->entry['slug']) ? (string) flextype('entries')->entry['slug'] : (string) end($parts); }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/UuidField.php b/src/flextype/app/Foundation/Entries/Fields/UuidField.php index 3406776a..c0522a4e 100644 --- a/src/flextype/app/Foundation/Entries/Fields/UuidField.php +++ b/src/flextype/app/Foundation/Entries/Fields/UuidField.php @@ -9,12 +9,12 @@ declare(strict_types=1); use Ramsey\Uuid\Uuid; -if ($flextype->container('registry')->get('flextype.settings.entries.fields.uuid.enabled')) { - $flextype->container('emitter')->addListener('onEntryCreate', static function () use ($flextype) : void { - if (isset($flextype->container('entries')->entry_create_data['uuid'])) { - $flextype->container('entries')->entry_create_data['uuid'] = $flextype->container('entries')->entry_create_data['uuid']; +if (flextype('registry')->get('flextype.settings.entries.fields.uuid.enabled')) { + flextype('emitter')->addListener('onEntryCreate', static function () : void { + if (isset(flextype('entries')->entry_create_data['uuid'])) { + flextype('entries')->entry_create_data['uuid'] = flextype('entries')->entry_create_data['uuid']; } else { - $flextype->container('entries')->entry_create_data['uuid'] = Uuid::uuid4()->toString(); + flextype('entries')->entry_create_data['uuid'] = Uuid::uuid4()->toString(); } }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/VisibilityField.php b/src/flextype/app/Foundation/Entries/Fields/VisibilityField.php index b393e2b4..30d53714 100644 --- a/src/flextype/app/Foundation/Entries/Fields/VisibilityField.php +++ b/src/flextype/app/Foundation/Entries/Fields/VisibilityField.php @@ -7,26 +7,26 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if ($flextype->container('registry')->get('flextype.settings.entries.fields.visibility.enabled')) { +if (flextype('registry')->get('flextype.settings.entries.fields.visibility.enabled')) { $visibility = [ 'draft' => 'draft', 'hidden' => 'hidden', 'visible' => 'visible', ]; - $flextype->container('emitter')->addListener('onEntryAfterInitialized', static function () use ($flextype, $visibility) : void { - if (isset($flextype->container('entries')->entry['visibility']) && in_array($flextype->container('entries')->entry['visibility'], $visibility)) { - $flextype->container('entries')->entry['visibility'] = (string) $visibility[$flextype->container('entries')->entry['visibility']]; + flextype('emitter')->addListener('onEntryAfterInitialized', static function () use ($visibility) : void { + if (isset(flextype('entries')->entry['visibility']) && in_array(flextype('entries')->entry['visibility'], $visibility)) { + flextype('entries')->entry['visibility'] = (string) $visibility[flextype('entries')->entry['visibility']]; } else { - $flextype->container('entries')->entry['visibility'] = (string) $visibility['visible']; + flextype('entries')->entry['visibility'] = (string) $visibility['visible']; } }); - $flextype->container('emitter')->addListener('onEntryCreate', static function () use ($flextype, $visibility) : void { - if (isset($flextype->container('entries')->entry_create_data['visibility']) && in_array($flextype->container('entries')->entry_create_data['visibility'], $visibility)) { - $flextype->container('entries')->entry_create_data['visibility'] = $flextype->container('entries')->entry_create_data['visibility']; + flextype('emitter')->addListener('onEntryCreate', static function () use ($visibility) : void { + if (isset(flextype('entries')->entry_create_data['visibility']) && in_array(flextype('entries')->entry_create_data['visibility'], $visibility)) { + flextype('entries')->entry_create_data['visibility'] = flextype('entries')->entry_create_data['visibility']; } else { - $flextype->container('entries')->entry_create_data['visibility'] = 'visible'; + flextype('entries')->entry_create_data['visibility'] = 'visible'; } }); } diff --git a/src/flextype/app/Foundation/Media/MediaFiles.php b/src/flextype/app/Foundation/Media/MediaFiles.php index bfbc2e13..07a39a13 100644 --- a/src/flextype/app/Foundation/Media/MediaFiles.php +++ b/src/flextype/app/Foundation/Media/MediaFiles.php @@ -46,16 +46,16 @@ class MediaFiles /** * Flextype Application */ - protected $flextype; + /** * Constructor * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -79,11 +79,11 @@ class MediaFiles Filesystem::createDir($upload_metadata_folder); } - $accept_file_types = $this->flextype->container('registry')->get('flextype.settings.media.accept_file_types'); - $max_file_size = $this->flextype->container('registry')->get('flextype.settings.media.max_file_size'); - $safe_names = $this->flextype->container('registry')->get('flextype.settings.media.safe_names'); - $max_image_width = $this->flextype->container('registry')->get('flextype.settings.media.max_image_width'); - $max_image_height = $this->flextype->container('registry')->get('flextype.settings.media.max_image_height'); + $accept_file_types = flextype('registry')->get('flextype.settings.media.accept_file_types'); + $max_file_size = flextype('registry')->get('flextype.settings.media.max_file_size'); + $safe_names = flextype('registry')->get('flextype.settings.media.safe_names'); + $max_image_width = flextype('registry')->get('flextype.settings.media.max_image_width'); + $max_image_height = flextype('registry')->get('flextype.settings.media.max_image_height'); $exact = false; $chmod = 0644; @@ -159,7 +159,7 @@ class MediaFiles if ($safe_names === true) { // Remove spaces from the filename - $filename = $this->flextype->container('slugify')->slugify(pathinfo($filename)['filename']) . '.' . pathinfo($filename)['extension']; + $filename = flextype('slugify')->slugify(pathinfo($filename)['filename']) . '.' . pathinfo($filename)['extension']; } if (! is_dir($upload_folder) or ! is_writable(realpath($upload_folder))) { @@ -177,25 +177,25 @@ class MediaFiles $img = Image::make($filename); // now you are able to resize the instance - if ($this->flextype->container('registry')->get('flextype.settings.media.image_width') > 0 && $this->flextype->container('registry')->get('flextype.settings.media.image_height') > 0) { - $img->resize($this->flextype->container('registry')->get('flextype.settings.media.image_width'), $this->flextype->container('registry')->get('flextype.settings.media.image_height'), static function ($constraint) : void { + if (flextype('registry')->get('flextype.settings.media.image_width') > 0 && flextype('registry')->get('flextype.settings.media.image_height') > 0) { + $img->resize(flextype('registry')->get('flextype.settings.media.image_width'), flextype('registry')->get('flextype.settings.media.image_height'), static function ($constraint) : void { $constraint->aspectRatio(); $constraint->upsize(); }); - } elseif ($this->flextype->container('registry')->get('flextype.settings.media.image_width') > 0) { - $img->resize($this->flextype->container('registry')->get('flextype.settings.media.image_width'), null, static function ($constraint) : void { + } elseif (flextype('registry')->get('flextype.settings.media.image_width') > 0) { + $img->resize(flextype('registry')->get('flextype.settings.media.image_width'), null, static function ($constraint) : void { $constraint->aspectRatio(); $constraint->upsize(); }); - } elseif ($this->flextype->container('registry')->get('flextype.settings.media.image_height') > 0) { - $img->resize(null, $this->flextype->container('registry')->get('flextype.settings.media.image_height'), static function ($constraint) : void { + } elseif (flextype('registry')->get('flextype.settings.media.image_height') > 0) { + $img->resize(null, flextype('registry')->get('flextype.settings.media.image_height'), static function ($constraint) : void { $constraint->aspectRatio(); $constraint->upsize(); }); } // finally we save the image as a new file - $img->save($filename, $this->flextype->container('registry')->get('flextype.settings.media.image_quality')); + $img->save($filename, flextype('registry')->get('flextype.settings.media.image_quality')); // destroy $img->destroy(); @@ -220,7 +220,7 @@ class MediaFiles Filesystem::write( $upload_metadata_folder . basename($filename) . '.yaml', - $this->flextype->container('yaml')->encode($metadata) + flextype('yaml')->encode($metadata) ); // Return new file path @@ -264,18 +264,18 @@ class MediaFiles { $result = []; - if (Filesystem::has($this->flextype->container('media_files_meta')->getFileMetaLocation($path))) { - $result = $this->flextype->container('yaml')->decode(Filesystem::read($this->flextype->container('media_files_meta')->getFileMetaLocation($path))); + if (Filesystem::has(flextype('media_files_meta')->getFileMetaLocation($path))) { + $result = flextype('yaml')->decode(Filesystem::read(flextype('media_files_meta')->getFileMetaLocation($path))); - $result['filename'] = pathinfo(str_replace('/.meta', '', $this->flextype->container('media_files_meta')->getFileMetaLocation($path)))['filename']; - $result['basename'] = explode('.', basename($this->flextype->container('media_files_meta')->getFileMetaLocation($path)))[0]; + $result['filename'] = pathinfo(str_replace('/.meta', '', flextype('media_files_meta')->getFileMetaLocation($path)))['filename']; + $result['basename'] = explode('.', basename(flextype('media_files_meta')->getFileMetaLocation($path)))[0]; $result['extension'] = ltrim(strstr($path, '.'), '.'); - $result['dirname'] = pathinfo(str_replace('/.meta', '', $this->flextype->container('media_files_meta')->getFileMetaLocation($path)))['dirname']; + $result['dirname'] = pathinfo(str_replace('/.meta', '', flextype('media_files_meta')->getFileMetaLocation($path)))['dirname']; $result['url'] = 'project/uploads/' . $path; - if ($this->flextype->container('registry')->has('flextype.settings.url') && $this->flextype->container('registry')->get('flextype.settings.url') !== '') { - $full_url = $this->flextype->container('registry')->get('flextype.settings.url'); + if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') { + $full_url = flextype('registry')->get('flextype.settings.url'); } else { $full_url = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); } @@ -297,18 +297,18 @@ class MediaFiles { $result = []; - foreach (Filesystem::listContents($this->flextype->container('media_folders_meta')->getDirMetaLocation($path)) as $file) { - $result[$file['basename']] = $this->flextype->container('yaml')->decode(Filesystem::read($file['path'])); + foreach (Filesystem::listContents(flextype('media_folders_meta')->getDirMetaLocation($path)) as $file) { + $result[$file['basename']] = flextype('yaml')->decode(Filesystem::read($file['path'])); - $result[$file['basename']]['filename'] = pathinfo(str_replace('/.meta', '', $this->flextype->container('media_files_meta')->getFileMetaLocation($file['basename'])))['filename']; - $result[$file['basename']]['basename'] = explode('.', basename($this->flextype->container('media_files_meta')->getFileMetaLocation($file['basename'])))[0]; + $result[$file['basename']]['filename'] = pathinfo(str_replace('/.meta', '', flextype('media_files_meta')->getFileMetaLocation($file['basename'])))['filename']; + $result[$file['basename']]['basename'] = explode('.', basename(flextype('media_files_meta')->getFileMetaLocation($file['basename'])))[0]; $result[$file['basename']]['extension'] = ltrim(strstr($file['basename'], '.'), '.'); $result[$file['basename']]['dirname'] = pathinfo(str_replace('/.meta', '', $file['path']))['dirname']; $result[$file['basename']]['url'] = 'project/uploads/' . $path . '/' . $file['basename']; - if ($this->flextype->container('registry')->has('flextype.settings.url') && $this->flextype->container('registry')->get('flextype.settings.url') !== '') { - $full_url = $this->flextype->container('registry')->get('flextype.settings.url'); + if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') { + $full_url = flextype('registry')->get('flextype.settings.url'); } else { $full_url = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); } @@ -331,8 +331,8 @@ class MediaFiles */ public function rename(string $id, string $new_id) : bool { - if (! Filesystem::has($this->getFileLocation($new_id)) && ! Filesystem::has($this->flextype->container('media_files_meta')->getFileMetaLocation($new_id))) { - return rename($this->getFileLocation($id), $this->getFileLocation($new_id)) && rename($this->flextype->container('media_files_meta')->getFileMetaLocation($id), $this->flextype->container('media_files_meta')->getFileMetaLocation($new_id)); + if (! Filesystem::has($this->getFileLocation($new_id)) && ! Filesystem::has(flextype('media_files_meta')->getFileMetaLocation($new_id))) { + return rename($this->getFileLocation($id), $this->getFileLocation($new_id)) && rename(flextype('media_files_meta')->getFileMetaLocation($id), flextype('media_files_meta')->getFileMetaLocation($new_id)); } return false; @@ -350,7 +350,7 @@ class MediaFiles public function delete(string $id) : bool { return Filesystem::delete($this->getFileLocation($id)) && - Filesystem::delete($this->flextype->container('media_files_meta')->getFileMetaLocation($id)); + Filesystem::delete(flextype('media_files_meta')->getFileMetaLocation($id)); } /** @@ -365,7 +365,7 @@ class MediaFiles public function has(string $id) : bool { return Filesystem::has($this->getFileLocation($id)) && - Filesystem::has($this->flextype->container('media_files_meta')->getFileMetaLocation($id)); + Filesystem::has(flextype('media_files_meta')->getFileMetaLocation($id)); } /** @@ -380,19 +380,19 @@ class MediaFiles */ public function copy(string $id, string $new_id) : bool { - if (! Filesystem::has($this->getFileLocation($new_id)) && ! Filesystem::has($this->flextype->container('media_files_meta')->getFileMetaLocation($new_id))) { + if (! Filesystem::has($this->getFileLocation($new_id)) && ! Filesystem::has(flextype('media_files_meta')->getFileMetaLocation($new_id))) { Filesystem::copy( $this->getFileLocation($id), $this->getFileLocation($new_id), false ); Filesystem::copy( - $this->flextype->container('media_files_meta')->getFileMetaLocation($id), - $this->flextype->container('media_files_meta')->getFileMetaLocation($new_id), + flextype('media_files_meta')->getFileMetaLocation($id), + flextype('media_files_meta')->getFileMetaLocation($new_id), false ); - return Filesystem::has($this->getFileLocation($new_id)) && Filesystem::has($this->flextype->container('media_files_meta')->getFileMetaLocation($new_id)) === true; + return Filesystem::has($this->getFileLocation($new_id)) && Filesystem::has(flextype('media_files_meta')->getFileMetaLocation($new_id)) === true; } return false; diff --git a/src/flextype/app/Foundation/Media/MediaFilesMeta.php b/src/flextype/app/Foundation/Media/MediaFilesMeta.php index bf10c87f..a8ebea45 100644 --- a/src/flextype/app/Foundation/Media/MediaFilesMeta.php +++ b/src/flextype/app/Foundation/Media/MediaFilesMeta.php @@ -17,16 +17,16 @@ class MediaFilesMeta /** * Flextype Application */ - protected $flextype; + /** * Constructor * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -42,12 +42,12 @@ class MediaFilesMeta */ public function update(string $id, string $field, string $value) : bool { - $file_data = $this->flextype->container('yaml')->decode(Filesystem::read($this->getFileMetaLocation($id))); + $file_data = flextype('yaml')->decode(Filesystem::read($this->getFileMetaLocation($id))); if (Arrays::has($file_data, $field)) { Arrays::set($file_data, $field, $value); - return Filesystem::write($this->getFileMetaLocation($id), $this->flextype->container('yaml')->encode($file_data)); + return Filesystem::write($this->getFileMetaLocation($id), flextype('yaml')->encode($file_data)); } return false; @@ -66,12 +66,12 @@ class MediaFilesMeta */ public function add(string $id, string $field, string $value) : bool { - $file_data = $this->flextype->container('yaml')->decode(Filesystem::read($this->getFileMetaLocation($id))); + $file_data = flextype('yaml')->decode(Filesystem::read($this->getFileMetaLocation($id))); if (! Arrays::has($file_data, $field)) { Arrays::set($file_data, $field, $value); - return Filesystem::write($this->getFileMetaLocation($id), $this->flextype->container('yaml')->encode($file_data)); + return Filesystem::write($this->getFileMetaLocation($id), flextype('yaml')->encode($file_data)); } return false; @@ -89,12 +89,12 @@ class MediaFilesMeta */ public function delete(string $id, string $field) : bool { - $file_data = $this->flextype->container('yaml')->decode(Filesystem::read($this->getFileMetaLocation($id))); + $file_data = flextype('yaml')->decode(Filesystem::read($this->getFileMetaLocation($id))); if (Arrays::has($file_data, $field)) { Arrays::delete($file_data, $field); - return Filesystem::write($this->getFileMetaLocation($id), $this->flextype->container('yaml')->encode($file_data)); + return Filesystem::write($this->getFileMetaLocation($id), flextype('yaml')->encode($file_data)); } return false; diff --git a/src/flextype/app/Foundation/Media/MediaFolders.php b/src/flextype/app/Foundation/Media/MediaFolders.php index 49c4937c..1a23583f 100644 --- a/src/flextype/app/Foundation/Media/MediaFolders.php +++ b/src/flextype/app/Foundation/Media/MediaFolders.php @@ -20,16 +20,16 @@ class MediaFolders /** * Flextype Application */ - protected $flextype; + /** * Constructor * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -60,13 +60,13 @@ class MediaFolders { $result = []; - if (Filesystem::has($this->flextype->container('media_folders_meta')->getDirMetaLocation($path))) { + if (Filesystem::has(flextype('media_folders_meta')->getDirMetaLocation($path))) { $result['path'] = $path; - $result['full_path'] = str_replace('/.meta', '', $this->flextype->container('media_folders_meta')->getDirMetaLocation($path)); + $result['full_path'] = str_replace('/.meta', '', flextype('media_folders_meta')->getDirMetaLocation($path)); $result['url'] = 'project/uploads/' . $path; - if ($this->flextype->container('registry')->has('flextype.settings.url') && $this->flextype->container('registry')->get('flextype.settings.url') !== '') { - $full_url = $this->flextype->container('registry')->get('flextype.settings.url'); + if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') { + $full_url = flextype('registry')->get('flextype.settings.url'); } else { $full_url = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); } @@ -88,7 +88,7 @@ class MediaFolders { $result = []; - foreach (Filesystem::listContents($this->flextype->container('media_folders_meta')->getDirMetaLocation($path)) as $folder) { + foreach (Filesystem::listContents(flextype('media_folders_meta')->getDirMetaLocation($path)) as $folder) { if ($folder['type'] !== 'dir') { continue; } @@ -110,8 +110,8 @@ class MediaFolders */ public function create(string $id) : bool { - if (! Filesystem::has($this->getDirLocation($id)) && ! Filesystem::has($this->flextype->container('media_folders_meta')->getDirMetaLocation($id))) { - return Filesystem::createDir($this->getDirLocation($id)) && Filesystem::createDir($this->flextype->container('media_folders_meta')->getDirMetaLocation($id)); + if (! Filesystem::has($this->getDirLocation($id)) && ! Filesystem::has(flextype('media_folders_meta')->getDirMetaLocation($id))) { + return Filesystem::createDir($this->getDirLocation($id)) && Filesystem::createDir(flextype('media_folders_meta')->getDirMetaLocation($id)); } return false; @@ -129,8 +129,8 @@ class MediaFolders */ public function rename(string $id, string $new_id) : bool { - if (! Filesystem::has($this->getDirLocation($new_id)) && ! Filesystem::has($this->flextype->container('media_folders_meta')->getDirMetaLocation($new_id))) { - return rename($this->getDirLocation($id), $this->getDirLocation($new_id)) && rename($this->flextype->container('media_folders_meta')->getDirMetaLocation($id), $this->flextype->container('media_folders_meta')->getDirMetaLocation($new_id)); + if (! Filesystem::has($this->getDirLocation($new_id)) && ! Filesystem::has(flextype('media_folders_meta')->getDirMetaLocation($new_id))) { + return rename($this->getDirLocation($id), $this->getDirLocation($new_id)) && rename(flextype('media_folders_meta')->getDirMetaLocation($id), flextype('media_folders_meta')->getDirMetaLocation($new_id)); } return false; @@ -148,19 +148,19 @@ class MediaFolders */ public function copy(string $id, string $new_id) : bool { - if (! Filesystem::has($this->getDirLocation($new_id)) && ! Filesystem::has($this->flextype->container('media_folders_meta')->getDirMetaLocation($new_id))) { + if (! Filesystem::has($this->getDirLocation($new_id)) && ! Filesystem::has(flextype('media_folders_meta')->getDirMetaLocation($new_id))) { Filesystem::copy( $this->getDirLocation($id), $this->getDirLocation($new_id), true ); Filesystem::copy( - $this->flextype->container('media_folders_meta')->getDirMetaLocation($id), - $this->flextype->container('media_folders_meta')->getDirMetaLocation($new_id), + flextype('media_folders_meta')->getDirMetaLocation($id), + flextype('media_folders_meta')->getDirMetaLocation($new_id), true ); - return Filesystem::has($this->getDirLocation($new_id)) && Filesystem::has($this->flextype->container('media_folders_meta')->getDirMetaLocation($new_id)) === true; + return Filesystem::has($this->getDirLocation($new_id)) && Filesystem::has(flextype('media_folders_meta')->getDirMetaLocation($new_id)) === true; } return false; @@ -178,7 +178,7 @@ class MediaFolders public function delete(string $id) : bool { return Filesystem::deleteDir($this->getDirLocation($id)) && - Filesystem::deleteDir($this->flextype->container('media_folders_meta')->getDirMetaLocation($id)); + Filesystem::deleteDir(flextype('media_folders_meta')->getDirMetaLocation($id)); } /** diff --git a/src/flextype/app/Foundation/Media/MediaFoldersMeta.php b/src/flextype/app/Foundation/Media/MediaFoldersMeta.php index ff8761d9..2e9d8ae7 100644 --- a/src/flextype/app/Foundation/Media/MediaFoldersMeta.php +++ b/src/flextype/app/Foundation/Media/MediaFoldersMeta.php @@ -14,16 +14,16 @@ class MediaFoldersMeta /** * Flextype Application */ - protected $flextype; + /** * Constructor * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** diff --git a/src/flextype/app/Foundation/Plugins.php b/src/flextype/app/Foundation/Plugins.php index b4dadb6f..5cde3ba2 100755 --- a/src/flextype/app/Foundation/Plugins.php +++ b/src/flextype/app/Foundation/Plugins.php @@ -27,7 +27,7 @@ class Plugins /** * Flextype Application */ - protected $flextype; + /** * Locales array @@ -41,10 +41,10 @@ class Plugins * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; - $this->locales = $this->flextype->container('yaml')->decode(Filesystem::read(ROOT_DIR . '/src/flextype/locales.yaml')); + + $this->locales = flextype('yaml')->decode(Filesystem::read(ROOT_DIR . '/src/flextype/locales.yaml')); } /** @@ -67,10 +67,10 @@ class Plugins public function init() : void { // Set empty plugins item - $this->flextype->container('registry')->set('plugins', []); + flextype('registry')->set('plugins', []); // Set locale - $locale = $this->flextype->container('registry')->get('flextype.settings.locale'); + $locale = flextype('registry')->get('flextype.settings.locale'); // Get plugins list $plugins_list = $this->getPluginsList(); @@ -84,15 +84,15 @@ class Plugins } // Get plugins from cache or scan plugins folder and create new plugins cache item - if ($this->flextype->container('cache')->contains($plugins_cache_id)) { - $this->flextype->container('registry')->set('plugins', $this->flextype->container('cache')->fetch($plugins_cache_id)); + if (flextype('cache')->contains($plugins_cache_id)) { + flextype('registry')->set('plugins', flextype('cache')->fetch($plugins_cache_id)); - if ($this->flextype->container('cache')->contains($locale)) { - I18n::add($this->flextype->container('cache')->fetch($locale), $locale); + if (flextype('cache')->contains($locale)) { + I18n::add(flextype('cache')->fetch($locale), $locale); } else { // Save plugins dictionary $dictionary = $this->getPluginsDictionary($plugins_list, $locale); - $this->flextype->container('cache')->save($locale, $dictionary[$locale]); + flextype('cache')->save($locale, $dictionary[$locale]); } } else { // Init plugin configs @@ -123,7 +123,7 @@ class Plugins // Get default plugin settings content $default_plugin_settings_file_content = Filesystem::read($default_plugin_settings_file); - $default_plugin_settings = $this->flextype->container('yaml')->decode($default_plugin_settings_file_content); + $default_plugin_settings = flextype('yaml')->decode($default_plugin_settings_file_content); // Create project plugin settings file ! Filesystem::has($project_plugin_settings_file) and Filesystem::write($project_plugin_settings_file, $default_plugin_settings_file_content); @@ -134,7 +134,7 @@ class Plugins if (trim($project_plugin_settings_file_content) === '') { $project_plugin_settings = []; } else { - $project_plugin_settings = $this->flextype->container('yaml')->decode($project_plugin_settings_file_content); + $project_plugin_settings = flextype('yaml')->decode($project_plugin_settings_file_content); } // Check if default plugin manifest file exists @@ -144,7 +144,7 @@ class Plugins // Get default plugin manifest content $default_plugin_manifest_file_content = Filesystem::read($default_plugin_manifest_file); - $default_plugin_manifest = $this->flextype->container('yaml')->decode($default_plugin_manifest_file_content); + $default_plugin_manifest = flextype('yaml')->decode($default_plugin_manifest_file_content); // Merge plugin settings and manifest data $plugins[$plugin['dirname']]['manifest'] = $default_plugin_manifest; @@ -172,17 +172,17 @@ class Plugins $plugins = $this->getValidPluginsDependencies($plugins); // Save plugins list - $this->flextype->container('registry')->set('plugins', $plugins); - $this->flextype->container('cache')->save($plugins_cache_id, $plugins); + flextype('registry')->set('plugins', $plugins); + flextype('cache')->save($plugins_cache_id, $plugins); // Save plugins dictionary $dictionary = $this->getPluginsDictionary($plugins_list, $locale); - $this->flextype->container('cache')->save($locale, $dictionary[$locale]); + flextype('cache')->save($locale, $dictionary[$locale]); } - $this->includeEnabledPlugins($this->flextype); + $this->includeEnabledPlugins(); - $this->flextype->container('emitter')->emit('onPluginsInitialized'); + flextype('emitter')->emit('onPluginsInitialized'); } /** @@ -205,7 +205,7 @@ class Plugins throw new RuntimeException('Load file: ' . $language_file . ' - failed!'); } - $translates = $this->flextype->container('yaml')->decode($content); + $translates = flextype('yaml')->decode($content); I18n::add($translates, $locale); } @@ -270,7 +270,7 @@ class Plugins foreach ($plugin_data['manifest']['dependencies'] as $dependency => $constraints) { // Verify flextype version if ($dependency === 'flextype') { - if (! Semver::satisfies($this->flextype->container('registry')->get('flextype.manifest.version'), $constraints)) { + if (! Semver::satisfies(flextype('registry')->get('flextype.manifest.version'), $constraints)) { $verified = false; // Remove plugin where it is require this dependency @@ -370,14 +370,14 @@ class Plugins * * @access private */ - private function includeEnabledPlugins($flextype) : void + private function includeEnabledPlugins() : void { - if (! is_array($this->flextype->container('registry')->get('plugins')) || count($this->flextype->container('registry')->get('plugins')) <= 0) { + if (! is_array(flextype('registry')->get('plugins')) || count(flextype('registry')->get('plugins')) <= 0) { return; } - foreach ($this->flextype->container('registry')->get('plugins') as $plugin_name => $plugin) { - if (! $this->flextype->container('registry')->get('plugins.' . $plugin_name . '.settings.enabled')) { + foreach (flextype('registry')->get('plugins') as $plugin_name => $plugin) { + if (! flextype('registry')->get('plugins.' . $plugin_name . '.settings.enabled')) { continue; } diff --git a/src/flextype/app/Support/Parsers/Markdown.php b/src/flextype/app/Support/Parsers/Markdown.php index 31003265..eb63ee8a 100644 --- a/src/flextype/app/Support/Parsers/Markdown.php +++ b/src/flextype/app/Support/Parsers/Markdown.php @@ -16,7 +16,7 @@ class Markdown /** * Flextype Application */ - protected $flextype; + /** * Markdown @@ -28,9 +28,9 @@ class Markdown * * @access public */ - public function __construct($flextype, $markdown) + public function __construct($markdown) { - $this->flextype = $flextype; + $this->markdown = $markdown; } @@ -44,15 +44,15 @@ class Markdown */ public function parse(string $input, bool $cache = true) : string { - if ($cache === true && $this->flextype->container('registry')->get('flextype.settings.cache.enabled') === true) { + if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) { $key = $this->getCacheID($input); - if ($data_from_cache = $this->flextype->container('cache')->fetch($key)) { + if ($data_from_cache = flextype('cache')->fetch($key)) { return $data_from_cache; } $data = $this->_parse($input); - $this->flextype->container('cache')->save($key, $data); + flextype('cache')->save($key, $data); return $data; } diff --git a/src/flextype/app/Support/Parsers/Shortcode.php b/src/flextype/app/Support/Parsers/Shortcode.php index 67eae696..d7bb3f8d 100644 --- a/src/flextype/app/Support/Parsers/Shortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcode.php @@ -13,11 +13,6 @@ use function md5; class Shortcode { - /** - * Flextype Application - */ - protected $flextype; - /** * Shortcode Fasade */ @@ -28,9 +23,8 @@ class Shortcode * * @access public */ - public function __construct($flextype, $shortcode) + public function __construct($shortcode) { - $this->flextype = $flextype; $this->shortcode = $shortcode; } @@ -92,15 +86,15 @@ class Shortcode */ public function process(string $input, bool $cache = true) { - if ($cache === true && $this->flextype->container('registry')->get('flextype.settings.cache.enabled') === true) { + if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) { $key = $this->getCacheID($input); - if ($data_from_cache = $this->flextype->container('cache')->fetch($key)) { + if ($data_from_cache = flextype('cache')->fetch($key)) { return $data_from_cache; } $data = $this->shortcode->process($input); - $this->flextype->container('cache')->save($key, $data); + flextype('cache')->save($key, $data); return $data; } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php index 1d1ca1f1..8683d712 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php @@ -10,9 +10,9 @@ declare(strict_types=1); use Flextype\Component\Arrays\Arrays; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.entries.enabled')) { +if (flextype('registry')->get('flextype.settings.shortcode.shortcodes.entries.enabled')) { // Shortcode: [entries_fetch id="entry-id" field="field-name" default="default-value"] - $flextype->container('shortcode')->addHandler('entries_fetch', static function (ShortcodeInterface $s) use ($flextype) { - return Arrays::get($flextype->container('entries')->fetch($s->getParameter('id')), $s->getParameter('field'), $s->getParameter('default')); + flextype('shortcode')->addHandler('entries_fetch', static function (ShortcodeInterface $s) { + return Arrays::get(flextype('entries')->fetch($s->getParameter('id')), $s->getParameter('field'), $s->getParameter('default')); }); } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php index f583d3c9..c41c1d48 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php @@ -11,11 +11,11 @@ use Thunder\Shortcode\EventHandler\FilterRawEventHandler; use Thunder\Shortcode\Events; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.raw.enabled')) { +if (flextype('registry')->get('flextype.settings.shortcode.shortcodes.raw.enabled')) { // Shortcode: [raw] - $flextype->container('shortcode')->addHandler('raw', static function (ShortcodeInterface $s) { + flextype('shortcode')->addHandler('raw', static function (ShortcodeInterface $s) { return $s->getContent(); }); - $flextype->container('shortcode')->addEventHandler(Events::FILTER_SHORTCODES, new FilterRawEventHandler(['raw'])); + flextype('shortcode')->addEventHandler(Events::FILTER_SHORTCODES, new FilterRawEventHandler(['raw'])); } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php index d7e9548f..dc77e53f 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php @@ -9,9 +9,9 @@ declare(strict_types=1); use Thunder\Shortcode\Shortcode\ShortcodeInterface; -if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.registry.enabled')) { +if (flextype('registry')->get('flextype.settings.shortcode.shortcodes.registry.enabled')) { // Shortcode: [registry_get name="item-name" default="default-value"] - $flextype->container('shortcode')->addHandler('registry_get', static function (ShortcodeInterface $s) use ($flextype) { - return $flextype->container('registry')->get($s->getParameter('name'), $s->getParameter('default')); + flextype('shortcode')->addHandler('registry_get', static function (ShortcodeInterface $s) { + return flextype('registry')->get($s->getParameter('name'), $s->getParameter('default')); }); } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php index ca49d79e..00c02320 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php @@ -10,11 +10,11 @@ declare(strict_types=1); use Slim\Http\Environment; use Slim\Http\Uri; -if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.url.enabled')) { +if (flextype('registry')->get('flextype.settings.shortcode.shortcodes.url.enabled')) { // Shortcode: [url] - $flextype->container('shortcode')->addHandler('url', static function () use ($flextype) { - if ($flextype->container('registry')->has('flextype.settings.url') && $flextype->container('registry')->get('flextype.settings.url') !== '') { - return $flextype->container('registry')->get('flextype.settings.url'); + flextype('shortcode')->addHandler('url', static function () { + if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') { + return flextype('registry')->get('flextype.settings.url'); } return Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); diff --git a/src/flextype/app/Support/Serializers/Frontmatter.php b/src/flextype/app/Support/Serializers/Frontmatter.php index 2fb89cf9..941e410a 100644 --- a/src/flextype/app/Support/Serializers/Frontmatter.php +++ b/src/flextype/app/Support/Serializers/Frontmatter.php @@ -25,16 +25,16 @@ class Frontmatter /** * Flextype Application */ - protected $flextype; + /** * Constructor * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -59,15 +59,15 @@ class Frontmatter */ public function decode(string $input, bool $cache = true) { - if ($cache === true && $this->flextype->container('registry')->get('flextype.settings.cache.enabled') === true) { + if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) { $key = $this->getCacheID($input); - if ($data_from_cache = $this->flextype->container('cache')->fetch($key)) { + if ($data_from_cache = flextype('cache')->fetch($key)) { return $data_from_cache; } $data = $this->_decode($input); - $this->flextype->container('cache')->save($key, $data); + flextype('cache')->save($key, $data); return $data; } @@ -83,10 +83,10 @@ class Frontmatter if (isset($input['content'])) { $content = $input['content']; Arrays::delete($input, 'content'); - $matter = $this->flextype->container('yaml')->encode($input); + $matter = flextype('yaml')->encode($input); } else { $content = ''; - $matter = $this->flextype->container('yaml')->encode($input); + $matter = flextype('yaml')->encode($input); } return '---' . "\n" . @@ -113,7 +113,7 @@ class Frontmatter return ['content' => trim($input)]; } - return $this->flextype->container('yaml')->decode(trim($parts[1]), false) + ['content' => trim(implode(PHP_EOL . '---' . PHP_EOL, array_slice($parts, 2)))]; + return flextype('yaml')->decode(trim($parts[1]), false) + ['content' => trim(implode(PHP_EOL . '---' . PHP_EOL, array_slice($parts, 2)))]; } protected function getCacheID($input) diff --git a/src/flextype/app/Support/Serializers/Json.php b/src/flextype/app/Support/Serializers/Json.php index 9b335566..8b056195 100644 --- a/src/flextype/app/Support/Serializers/Json.php +++ b/src/flextype/app/Support/Serializers/Json.php @@ -30,16 +30,16 @@ class Json /** * Flextype Application */ - protected $flextype; + /** * Constructor * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -71,15 +71,15 @@ class Json */ public function decode(string $input, bool $cache = true, bool $assoc = true, int $depth = 512, int $flags = 0) { - if ($cache === true && $this->flextype->container('registry')->get('flextype.settings.cache.enabled') === true) { + if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) { $key = $this->getCacheID($input); - if ($data_from_cache = $this->flextype->container('cache')->fetch($key)) { + if ($data_from_cache = flextype('cache')->fetch($key)) { return $data_from_cache; } $data = $this->_decode($input, $assoc, $depth, $flags); - $this->flextype->container('cache')->save($key, $data); + flextype('cache')->save($key, $data); return $data; } diff --git a/src/flextype/app/Support/Serializers/Yaml.php b/src/flextype/app/Support/Serializers/Yaml.php index 5a86bb0e..7013852d 100644 --- a/src/flextype/app/Support/Serializers/Yaml.php +++ b/src/flextype/app/Support/Serializers/Yaml.php @@ -36,16 +36,16 @@ class Yaml /** * Flextype Application */ - protected $flextype; + /** * Constructor * * @access public */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -88,15 +88,15 @@ class Yaml */ public function decode(string $input, bool $cache = true, int $flags = 0) : array { - if ($cache === true && $this->flextype->container('registry')->get('flextype.settings.cache.enabled') === true) { + if ($cache === true && flextype('registry')->get('flextype.settings.cache.enabled') === true) { $key = $this->getCacheID($input); - if ($data_from_cache = $this->flextype->container('cache')->fetch($key)) { + if ($data_from_cache = flextype('cache')->fetch($key)) { return $data_from_cache; } $data = $this->_decode($input, $flags); - $this->flextype->container('cache')->save($key, $data); + flextype('cache')->save($key, $data); return $data; } diff --git a/src/flextype/bootstrap.php b/src/flextype/bootstrap.php index f65fcef2..d334a7eb 100755 --- a/src/flextype/bootstrap.php +++ b/src/flextype/bootstrap.php @@ -39,9 +39,9 @@ $registry = new Registry(); include_once ROOT_DIR . '/src/flextype/preflight.php'; /** - * Create new application + * Create new Flextype Application */ -$flextype = new Flextype([ +$flextype = Flextype::getInstance([ 'settings' => [ 'debug' => $registry->get('flextype.settings.errors.display'), 'whoops.editor' => $registry->get('flextype.settings.whoops.editor'), @@ -76,18 +76,18 @@ include_once ROOT_DIR . '/src/flextype/app/Endpoints/images.php'; * Set internal encoding */ function_exists('mb_language') and mb_language('uni'); -function_exists('mb_regex_encoding') and mb_regex_encoding($flextype->container('registry')->get('flextype.settings.charset')); -function_exists('mb_internal_encoding') and mb_internal_encoding($flextype->container('registry')->get('flextype.settings.charset')); +function_exists('mb_regex_encoding') and mb_regex_encoding(flextype('registry')->get('flextype.settings.charset')); +function_exists('mb_internal_encoding') and mb_internal_encoding(flextype('registry')->get('flextype.settings.charset')); /** * Display Errors */ -if ($flextype->container('registry')->get('flextype.settings.errors.display')) { +if (flextype('registry')->get('flextype.settings.errors.display')) { /** * Add WhoopsMiddleware */ - $flextype->add(new WhoopsMiddleware($flextype)); + flextype()->add(new WhoopsMiddleware()); } else { error_reporting(0); } @@ -95,14 +95,14 @@ if ($flextype->container('registry')->get('flextype.settings.errors.display')) { /** * Set default timezone */ -date_default_timezone_set($flextype->container('registry')->get('flextype.settings.timezone')); +date_default_timezone_set(flextype('registry')->get('flextype.settings.timezone')); /** * Init shortocodes * * Load Flextype Shortcodes from directory /flextype/app/Support/Parsers/Shortcodes/ based on flextype.settings.shortcode.shortcodes array */ -$shortcodes = $flextype->container('registry')->get('flextype.settings.shortcode.shortcodes'); +$shortcodes = flextype('registry')->get('flextype.settings.shortcode.shortcodes'); foreach ($shortcodes as $shortcode_name => $shortcode) { $shortcode_file_path = ROOT_DIR . '/src/flextype/app/Support/Parsers/Shortcodes/' . str_replace('_', '', ucwords($shortcode_name, '_')) . 'Shortcode.php'; @@ -118,7 +118,7 @@ foreach ($shortcodes as $shortcode_name => $shortcode) { * * Load Flextype Entries fields from directory /flextype/app/Foundation/Entries/Fields/ based on flextype.settings.entries.fields array */ -$entry_fields = $flextype->container('registry')->get('flextype.settings.entries.fields'); +$entry_fields = flextype('registry')->get('flextype.settings.entries.fields'); foreach ($entry_fields as $field_name => $field) { $entry_field_file_path = ROOT_DIR . '/src/flextype/app/Foundation/Entries/Fields/' . str_replace('_', '', ucwords($field_name, '_')) . 'Field.php'; @@ -132,7 +132,7 @@ foreach ($entry_fields as $field_name => $field) { /** * Init plugins */ -$flextype->container('plugins')->init(); +flextype('plugins')->init(); /** * Enable lazy CORS @@ -141,9 +141,9 @@ $flextype->container('plugins')->init(); * This is important for third party web apps using Flextype, as without CORS, a JavaScript app hosted on example.com * couldn't access our APIs because they're hosted on another.com which is a different domain. */ -$flextype->container('cors')->init(); +flextype('cors')->init(); /** * Run application */ -$flextype->run(); +flextype()->run(); diff --git a/src/flextype/dependencies.php b/src/flextype/dependencies.php index 37f6bb72..785f3c28 100644 --- a/src/flextype/dependencies.php +++ b/src/flextype/dependencies.php @@ -52,24 +52,25 @@ use Thunder\Shortcode\ShortcodeFacade; use function date; use function extension_loaded; + /** * Supply a custom callable resolver, which resolves PSR-15 middlewares. */ -$flextype->container()['callableResolver'] = static function () use ($flextype) { - return new CallableResolver($flextype->container()); +flextype()->container()['callableResolver'] = static function () { + return new CallableResolver(flextype()->container()); }; /** * Add registry service to Flextype container */ -$flextype->container()['registry'] = static function () use ($registry) { +flextype()->container()['registry'] = static function () use ($registry) { return $registry; }; /** * Add logger service to Flextype container */ -$flextype->container()['logger'] = static function () { +flextype()->container()['logger'] = static function () { $logger = new Logger('flextype'); $logger->pushHandler(new StreamHandler(PATH['logs'] . '/' . date('Y-m-d') . '.log')); @@ -79,29 +80,29 @@ $flextype->container()['logger'] = static function () { /** * Add emitter service to Flextype container */ -$flextype->container()['emitter'] = static function () { +flextype()->container()['emitter'] = static function () { return new Emitter(); }; /** * Add slugify service to Flextype container */ -$flextype->container()['slugify'] = static function () use ($flextype) { +flextype()->container()['slugify'] = static function () { return new Slugify([ - 'separator' => $flextype->container('registry')->get('flextype.settings.slugify.separator'), - 'lowercase' => $flextype->container('registry')->get('flextype.settings.slugify.lowercase'), - 'trim' => $flextype->container('registry')->get('flextype.settings.slugify.trim'), - 'regexp' => $flextype->container('registry')->get('flextype.settings.slugify.regexp'), - 'lowercase_after_regexp' => $flextype->container('registry')->get('flextype.settings.slugify.lowercase_after_regexp'), - 'strip_tags' => $flextype->container('registry')->get('flextype.settings.slugify.strip_tags'), + 'separator' => flextype('registry')->get('flextype.settings.slugify.separator'), + 'lowercase' => flextype('registry')->get('flextype.settings.slugify.lowercase'), + 'trim' => flextype('registry')->get('flextype.settings.slugify.trim'), + 'regexp' => flextype('registry')->get('flextype.settings.slugify.regexp'), + 'lowercase_after_regexp' => flextype('registry')->get('flextype.settings.slugify.lowercase_after_regexp'), + 'strip_tags' => flextype('registry')->get('flextype.settings.slugify.strip_tags'), ]); }; /** * Adds the cache adapter to the Flextype container */ -$flextype->container()['cache_adapter'] = static function () use ($flextype) { - $driver_name = $flextype->container('registry')->get('flextype.settings.cache.driver'); +flextype()->container()['cache_adapter'] = static function () { + $driver_name = flextype('registry')->get('flextype.settings.cache.driver'); if (! $driver_name || $driver_name === 'auto') { if (extension_loaded('apcu')) { @@ -130,57 +131,57 @@ $flextype->container()['cache_adapter'] = static function () use ($flextype) { $adapter = "Flextype\\App\\Foundation\\Cache\\{$class_name}CacheAdapter"; - return new $adapter($flextype); + return new $adapter(); }; /** * Add cache service to Flextype container */ -$flextype->container()['cache'] = static function () use ($flextype) { - return new Cache($flextype); +flextype()->container()['cache'] = static function () { + return new Cache(); }; /** * Add shortcode parser service to Flextype container */ -$flextype->container()['shortcode'] = static function () use ($flextype) { - return new Shortcode($flextype, new ShortcodeFacade()); +flextype()->container()['shortcode'] = static function () { + return new Shortcode(new ShortcodeFacade()); }; /** * Add markdown parser service to Flextype container */ -$flextype->container()['markdown'] = static function () use ($flextype) { - return new Markdown($flextype, new ParsedownExtra()); +flextype()->container()['markdown'] = static function () { + return new Markdown(new ParsedownExtra()); }; /** * Add json serializer service to Flextype container */ -$flextype->container()['json'] = static function () use ($flextype) { - return new Json($flextype); +flextype()->container()['json'] = static function () { + return new Json(); }; /** * Add yaml serializer service to Flextype container */ -$flextype->container()['yaml'] = static function () use ($flextype) { - return new Yaml($flextype); +flextype()->container()['yaml'] = static function () { + return new Yaml(); }; /** * Add frontmatter serializer service to Flextype container */ -$flextype->container()['frontmatter'] = static function () use ($flextype) { - return new Frontmatter($flextype); +flextype()->container()['frontmatter'] = static function () { + return new Frontmatter(); }; /** * Add images service to Flextype container */ -$flextype->container()['images'] = static function () use ($flextype) { +flextype()->container()['images'] = static function () { // Get images settings - $imagesSettings = ['driver' => $flextype->container('registry')->get('flextype.settings.image.driver')]; + $imagesSettings = ['driver' => flextype('registry')->get('flextype.settings.image.driver')]; // Set source filesystem $source = new Filesystem( @@ -233,48 +234,48 @@ $flextype->container()['images'] = static function () use ($flextype) { /** * Add entries service to Flextype container */ -$flextype->container()['entries'] = static function () use ($flextype) { - return new Entries($flextype); +flextype()->container()['entries'] = static function () { + return new Entries(); }; /** * Add media folders service to Flextype container */ -$flextype->container()['media_folders'] = static function () use ($flextype) { - return new MediaFolders($flextype); +flextype()->container()['media_folders'] = static function () { + return new MediaFolders(); }; /** * Add media files service to Flextype container */ -$flextype->container()['media_files'] = static function () use ($flextype) { - return new MediaFiles($flextype); +flextype()->container()['media_files'] = static function () { + return new MediaFiles(); }; /** * Add media folders meta service to Flextype container */ -$flextype->container()['media_folders_meta'] = static function () use ($flextype) { - return new MediaFoldersMeta($flextype); +flextype()->container()['media_folders_meta'] = static function () { + return new MediaFoldersMeta(); }; /** * Add media files meta service to Flextype container */ -$flextype->container()['media_files_meta'] = static function () use ($flextype) { - return new MediaFilesMeta($flextype); +flextype()->container()['media_files_meta'] = static function () { + return new MediaFilesMeta(); }; /** * Add plugins service to Flextype container */ -$flextype->container()['plugins'] = static function () use ($flextype) { - return new Plugins($flextype); +flextype()->container()['plugins'] = static function () { + return new Plugins(); }; /** * Add cors service to Flextype container */ -$flextype->container()['cors'] = static function () use ($flextype) { - return new Cors($flextype); +flextype()->container()['cors'] = static function () { + return new Cors(); };