From dea72c711ff740b3b829d238fcf85648465143a0 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sat, 12 Jan 2019 23:55:38 +0100 Subject: Optimize and cleanup imports Signed-off-by: VirtualTam --- application/Languages.php | 1 - application/Thumbnailer.php | 2 +- application/api/ApiMiddleware.php | 3 +- application/api/ApiUtils.php | 2 +- application/api/controllers/ApiController.php | 7 ++- application/api/controllers/History.php | 69 ---------------------- application/api/controllers/HistoryController.php | 69 ++++++++++++++++++++++ application/api/controllers/Tags.php | 1 - .../api/exceptions/ApiLinkNotFoundException.php | 2 - .../api/exceptions/ApiTagNotFoundException.php | 2 - application/bookmark/LinkDB.php | 1 - application/feed/FeedBuilder.php | 1 - application/netscape/NetscapeBookmarkUtils.php | 2 +- application/render/PageBuilder.php | 4 +- application/updater/Updater.php | 2 +- 15 files changed, 80 insertions(+), 88 deletions(-) delete mode 100644 application/api/controllers/History.php create mode 100644 application/api/controllers/HistoryController.php (limited to 'application') diff --git a/application/Languages.php b/application/Languages.php index b9c5d0e8..5cda802e 100644 --- a/application/Languages.php +++ b/application/Languages.php @@ -3,7 +3,6 @@ namespace Shaarli; use Gettext\GettextTranslator; -use Gettext\Merge; use Gettext\Translations; use Gettext\Translator; use Gettext\TranslatorInterface; diff --git a/application/Thumbnailer.php b/application/Thumbnailer.php index 37ed97a1..a23f98e9 100644 --- a/application/Thumbnailer.php +++ b/application/Thumbnailer.php @@ -3,9 +3,9 @@ namespace Shaarli; use Shaarli\Config\ConfigManager; +use WebThumbnailer\Application\ConfigManager as WTConfigManager; use WebThumbnailer\Exception\WebThumbnailerException; use WebThumbnailer\WebThumbnailer; -use WebThumbnailer\Application\ConfigManager as WTConfigManager; /** * Class Thumbnailer diff --git a/application/api/ApiMiddleware.php b/application/api/ApiMiddleware.php index a2101f29..5ffb8c6d 100644 --- a/application/api/ApiMiddleware.php +++ b/application/api/ApiMiddleware.php @@ -1,9 +1,8 @@ history->getHistory(); - - // Return history operations from the {offset}th, starting from {since}. - $since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since')); - $offset = $request->getParam('offset'); - if (empty($offset)) { - $offset = 0; - } elseif (ctype_digit($offset)) { - $offset = (int) $offset; - } else { - throw new ApiBadParametersException('Invalid offset'); - } - - // limit parameter is either a number of links or 'all' for everything. - $limit = $request->getParam('limit'); - if (empty($limit)) { - $limit = count($history); - } elseif (ctype_digit($limit)) { - $limit = (int) $limit; - } else { - throw new ApiBadParametersException('Invalid limit'); - } - - $out = []; - $i = 0; - foreach ($history as $entry) { - if ((! empty($since) && $entry['datetime'] <= $since) || count($out) >= $limit) { - break; - } - if (++$i > $offset) { - $out[$i] = $entry; - $out[$i]['datetime'] = $out[$i]['datetime']->format(\DateTime::ATOM); - } - } - $out = array_values($out); - - return $response->withJson($out, 200, $this->jsonStyle); - } -} diff --git a/application/api/controllers/HistoryController.php b/application/api/controllers/HistoryController.php new file mode 100644 index 00000000..9afcfa26 --- /dev/null +++ b/application/api/controllers/HistoryController.php @@ -0,0 +1,69 @@ +history->getHistory(); + + // Return history operations from the {offset}th, starting from {since}. + $since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since')); + $offset = $request->getParam('offset'); + if (empty($offset)) { + $offset = 0; + } elseif (ctype_digit($offset)) { + $offset = (int) $offset; + } else { + throw new ApiBadParametersException('Invalid offset'); + } + + // limit parameter is either a number of links or 'all' for everything. + $limit = $request->getParam('limit'); + if (empty($limit)) { + $limit = count($history); + } elseif (ctype_digit($limit)) { + $limit = (int) $limit; + } else { + throw new ApiBadParametersException('Invalid limit'); + } + + $out = []; + $i = 0; + foreach ($history as $entry) { + if ((! empty($since) && $entry['datetime'] <= $since) || count($out) >= $limit) { + break; + } + if (++$i > $offset) { + $out[$i] = $entry; + $out[$i]['datetime'] = $out[$i]['datetime']->format(\DateTime::ATOM); + } + } + $out = array_values($out); + + return $response->withJson($out, 200, $this->jsonStyle); + } +} diff --git a/application/api/controllers/Tags.php b/application/api/controllers/Tags.php index 6dd78750..82f3ef74 100644 --- a/application/api/controllers/Tags.php +++ b/application/api/controllers/Tags.php @@ -4,7 +4,6 @@ namespace Shaarli\Api\Controllers; use Shaarli\Api\ApiUtils; use Shaarli\Api\Exceptions\ApiBadParametersException; -use Shaarli\Api\Exceptions\ApiLinkNotFoundException; use Shaarli\Api\Exceptions\ApiTagNotFoundException; use Slim\Http\Request; use Slim\Http\Response; diff --git a/application/api/exceptions/ApiLinkNotFoundException.php b/application/api/exceptions/ApiLinkNotFoundException.php index c727f4f0..7c2bb56e 100644 --- a/application/api/exceptions/ApiLinkNotFoundException.php +++ b/application/api/exceptions/ApiLinkNotFoundException.php @@ -2,8 +2,6 @@ namespace Shaarli\Api\Exceptions; -use Slim\Http\Response; - /** * Class ApiLinkNotFoundException * diff --git a/application/api/exceptions/ApiTagNotFoundException.php b/application/api/exceptions/ApiTagNotFoundException.php index eee152fe..66ace8bf 100644 --- a/application/api/exceptions/ApiTagNotFoundException.php +++ b/application/api/exceptions/ApiTagNotFoundException.php @@ -2,8 +2,6 @@ namespace Shaarli\Api\Exceptions; -use Slim\Http\Response; - /** * Class ApiTagNotFoundException * diff --git a/application/bookmark/LinkDB.php b/application/bookmark/LinkDB.php index 6041c088..c13a1141 100644 --- a/application/bookmark/LinkDB.php +++ b/application/bookmark/LinkDB.php @@ -6,7 +6,6 @@ use ArrayAccess; use Countable; use DateTime; use Iterator; -use Shaarli\Bookmark\LinkFilter; use Shaarli\Bookmark\Exception\LinkNotFoundException; use Shaarli\Exceptions\IOException; use Shaarli\FileUtils; diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php index 737a3128..b66f2f91 100644 --- a/application/feed/FeedBuilder.php +++ b/application/feed/FeedBuilder.php @@ -2,7 +2,6 @@ namespace Shaarli\Feed; use DateTime; -use Shaarli\Bookmark\LinkDB; /** * FeedBuilder class. diff --git a/application/netscape/NetscapeBookmarkUtils.php b/application/netscape/NetscapeBookmarkUtils.php index 2bf928c2..2fb1a4a6 100644 --- a/application/netscape/NetscapeBookmarkUtils.php +++ b/application/netscape/NetscapeBookmarkUtils.php @@ -5,12 +5,12 @@ namespace Shaarli\Netscape; use DateTime; use DateTimeZone; use Exception; +use Katzgrau\KLogger\Logger; use Psr\Log\LogLevel; use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\History; use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser; -use Katzgrau\KLogger\Logger; /** * Utilities to import and export bookmarks using the Netscape format diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index 1c5b9251..0569b67f 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -2,10 +2,10 @@ namespace Shaarli\Render; -use Shaarli\ApplicationUtils; use Exception; -use Shaarli\Bookmark\LinkDB; use RainTPL; +use Shaarli\ApplicationUtils; +use Shaarli\Bookmark\LinkDB; use Shaarli\Config\ConfigManager; use Shaarli\Thumbnailer; diff --git a/application/updater/Updater.php b/application/updater/Updater.php index 89f0ff7f..f12e3516 100644 --- a/application/updater/Updater.php +++ b/application/updater/Updater.php @@ -2,12 +2,12 @@ namespace Shaarli\Updater; -use Shaarli\ApplicationUtils; use Exception; use RainTPL; use ReflectionClass; use ReflectionException; use ReflectionMethod; +use Shaarli\ApplicationUtils; use Shaarli\Bookmark\LinkDB; use Shaarli\Bookmark\LinkFilter; use Shaarli\Config\ConfigJson; -- cgit v1.2.3