Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim4 #1

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-18.04
strategy:
matrix:
php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
php-versions: ['7.4', '8.0', '8.1']
name: PHP ${{ matrix.php-versions }}
steps:
- name: Set locales
Expand Down
5 changes: 3 additions & 2 deletions application/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function smallHash($text)
*/
function startsWith($haystack, $needle, $case = true)
{
$needle = $needle ?? '';
if ($case) {
return (strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0);
}
Expand Down Expand Up @@ -181,7 +182,7 @@ function generateLocation($referer, $host, $loopTerms = [])
}

$refererHost = parse_url($referer, PHP_URL_HOST);
if (!empty($referer) && (strpos($refererHost, $host) !== false || startsWith('?', $refererHost))) {
if (!empty($referer) && (strpos($refererHost ?? '', $host) !== false || startsWith('?', $refererHost))) {
$finalReferer = $referer;
}

Expand Down Expand Up @@ -292,7 +293,7 @@ function generate_api_secret($username, $salt)
*/
function normalize_spaces($string)
{
return preg_replace('/\s{2,}/', ' ', trim($string));
return preg_replace('/\s{2,}/', ' ', trim($string ?? ''));
}

/**
Expand Down
16 changes: 8 additions & 8 deletions application/api/ApiMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Shaarli\Api\Exceptions\ApiException;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Config\ConfigManager;
use Slim\Container;
use Slim\Http\Request;
use Pimple\Container;
use Slim\Http\Response;
use Slim\Http\ServerRequest;

/**
* Class ApiMiddleware
Expand Down Expand Up @@ -46,7 +46,7 @@ class ApiMiddleware
public function __construct($container)
{
$this->container = $container;
$this->conf = $this->container->get('conf');
$this->conf = $this->container['conf'];
$this->setLinkDb($this->conf);
}

Expand All @@ -56,7 +56,7 @@ public function __construct($container)
* - execute the controller
* - return the response
*
* @param Request $request Slim request
* @param ServerRequestInterface $request Slim request
* @param Response $response Slim response
* @param callable $next Next action
*
Expand Down Expand Up @@ -87,7 +87,7 @@ public function __invoke($request, $response, $next)
* Check the request validity (HTTP method, request value, etc.),
* that the API is enabled, and the JWT token validity.
*
* @param Request $request Slim request
* @param ServerRequestInterface $request Slim request
*
* @throws ApiAuthorizationException The API is disabled or the token is invalid.
*/
Expand All @@ -103,7 +103,7 @@ protected function checkRequest($request)
* Check that the JWT token is set and valid.
* The API secret setting must be set.
*
* @param Request $request Slim request
* @param ServerRequestInterface $request Slim request
*
* @throws ApiAuthorizationException The token couldn't be validated.
*/
Expand Down Expand Up @@ -145,8 +145,8 @@ protected function setLinkDb($conf)
{
$linkDb = new BookmarkFileService(
$conf,
$this->container->get('pluginManager'),
$this->container->get('history'),
$this->container['pluginManager'],
$this->container['history'],
new FlockMutex(fopen(SHAARLI_MUTEX_FILE, 'r'), 2),
true
);
Expand Down
8 changes: 4 additions & 4 deletions application/api/controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Shaarli\Bookmark\BookmarkServiceInterface;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Slim\Container;
use Pimple\Container;

/**
* Abstract Class ApiController
Expand Down Expand Up @@ -51,9 +51,9 @@ abstract class ApiController
public function __construct(Container $ci)
{
$this->ci = $ci;
$this->conf = $ci->get('conf');
$this->bookmarkService = $ci->get('db');
$this->history = $ci->get('history');
$this->conf = $ci['conf'];
$this->bookmarkService = $ci['db'];
$this->history = $ci['history'];
if ($this->conf->get('dev.debug', false)) {
$this->jsonStyle = JSON_PRETTY_PRINT;
} else {
Expand Down
4 changes: 2 additions & 2 deletions application/api/controllers/HistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Shaarli\Api\Controllers;

use Shaarli\Api\Exceptions\ApiBadParametersException;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand All @@ -30,7 +30,7 @@ public function getHistory($request, $response)
$history = $this->history->getHistory();

// Return history operations from the {offset}th, starting from {since}.
$since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since'));
$since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since', ''));
$offset = $request->getParam('offset');
if (empty($offset)) {
$offset = 0;
Expand Down
2 changes: 1 addition & 1 deletion application/api/controllers/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Shaarli\Api\Controllers;

use Shaarli\Bookmark\BookmarkFilter;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion application/api/controllers/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Shaarli\Api\ApiUtils;
use Shaarli\Api\Exceptions\ApiBadParametersException;
use Shaarli\Api\Exceptions\ApiLinkNotFoundException;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion application/api/controllers/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Shaarli\Api\Exceptions\ApiBadParametersException;
use Shaarli\Api\Exceptions\ApiTagNotFoundException;
use Shaarli\Bookmark\BookmarkFilter;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
20 changes: 10 additions & 10 deletions application/bookmark/BookmarkArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct()
*
* @return int Number of bookmarks
*/
public function count()
public function count(): int
{
return count($this->bookmarks);
}
Expand All @@ -70,7 +70,7 @@ public function count()
*
* @throws InvalidBookmarkException
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
if (
! $value instanceof Bookmark
Expand Down Expand Up @@ -106,7 +106,7 @@ public function offsetSet($offset, $value)
*
* @return bool true if it exists, false otherwise
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return array_key_exists($this->getBookmarkOffset($offset), $this->bookmarks);
}
Expand All @@ -116,7 +116,7 @@ public function offsetExists($offset)
*
* @param int $offset Bookmark ID
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
$realOffset = $this->getBookmarkOffset($offset);
$url = $this->bookmarks[$realOffset]->getUrl();
Expand All @@ -132,7 +132,7 @@ public function offsetUnset($offset)
*
* @return Bookmark|null The Bookmark if found, null otherwise
*/
public function offsetGet($offset)
public function offsetGet($offset): ?Bookmark
{
$realOffset = $this->getBookmarkOffset($offset);
return isset($this->bookmarks[$realOffset]) ? $this->bookmarks[$realOffset] : null;
Expand All @@ -143,7 +143,7 @@ public function offsetGet($offset)
*
* @return Bookmark corresponding to the current position
*/
public function current()
public function current(): Bookmark
{
return $this[$this->keys[$this->position]];
}
Expand All @@ -153,15 +153,15 @@ public function current()
*
* @return int Bookmark ID corresponding to the current position
*/
public function key()
public function key(): int
{
return $this->keys[$this->position];
}

/**
* Iterator - Moves forward to next element
*/
public function next()
public function next(): void
{
++$this->position;
}
Expand All @@ -171,7 +171,7 @@ public function next()
*
* Entries are sorted by date (latest first)
*/
public function rewind()
public function rewind(): void
{
$this->keys = array_keys($this->ids);
$this->position = 0;
Expand All @@ -182,7 +182,7 @@ public function rewind()
*
* @return bool true if the current Bookmark ID exists, false otherwise
*/
public function valid()
public function valid(): bool
{
return isset($this->keys[$this->position]);
}
Expand Down
3 changes: 1 addition & 2 deletions application/bookmark/BookmarkFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public function __construct(
public function findByHash(string $hash, string $privateKey = null): Bookmark
{
$bookmark = $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_HASH, $hash);
// PHP 7.3 introduced array_key_first() to avoid this hack
$first = reset($bookmark);
$first = $bookmark[array_key_first($bookmark)];
if (
!$this->isLoggedIn
&& $first->isPrivate()
Expand Down
2 changes: 1 addition & 1 deletion application/bookmark/LinkUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function tags_str2array(?string $tags, string $separator): array
// For whitespaces, we use the special \s regex character
$separator = $separator === ' ' ? '\s' : $separator;

return preg_split('/\s*' . $separator . '+\s*/', trim($tags) ?? '', -1, PREG_SPLIT_NO_EMPTY);
return preg_split('/\s*' . $separator . '+\s*/', trim($tags ?? ''), -1, PREG_SPLIT_NO_EMPTY);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion application/container/ShaarliContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Shaarli\Security\SessionManager;
use Shaarli\Thumbnailer;
use Shaarli\Updater\Updater;
use Slim\Container;
use Pimple\Container;

/**
* Extension of Slim container to document the injected objects.
Expand Down
2 changes: 1 addition & 1 deletion application/formatter/BookmarkDefaultFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function formatRealUrl($bookmark)
$prefix = rtrim($this->contextData['base_path'], '/') . '/';
}

return escape($prefix ?? '') . escape(ltrim($bookmark->getUrl(), '/'));
return escape($prefix ?? '') . escape(ltrim($bookmark->getUrl() ?? '', '/'));
}

return escape($bookmark->getUrl());
Expand Down
2 changes: 1 addition & 1 deletion application/front/ShaarliAdminMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Shaarli\Front;

use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion application/front/ShaarliMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Shaarli\Container\ShaarliContainer;
use Shaarli\Front\Exception\UnauthorizedException;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion application/front/controller/admin/ConfigureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Shaarli\Render\TemplatePage;
use Shaarli\Render\ThemeUtils;
use Shaarli\Thumbnailer;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;
use Throwable;

Expand Down
2 changes: 1 addition & 1 deletion application/front/controller/admin/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use DateTime;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Render\TemplatePage;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion application/front/controller/admin/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Psr\Http\Message\UploadedFileInterface;
use Shaarli\Render\TemplatePage;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion application/front/controller/admin/LogoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Shaarli\Security\CookieManager;
use Shaarli\Security\LoginManager;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion application/front/controller/admin/ManageTagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Shaarli\Bookmark\BookmarkFilter;
use Shaarli\Render\TemplatePage;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion application/front/controller/admin/MetadataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Shaarli\Front\Controller\Admin;

use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion application/front/controller/admin/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Shaarli\Front\Exception\OpenShaarliPasswordException;
use Shaarli\Front\Exception\ShaarliFrontException;
use Shaarli\Render\TemplatePage;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;
use Throwable;

Expand Down
2 changes: 1 addition & 1 deletion application/front/controller/admin/PluginsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Exception;
use Shaarli\Render\TemplatePage;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
2 changes: 1 addition & 1 deletion application/front/controller/admin/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Shaarli\Helper\ApplicationUtils;
use Shaarli\Helper\FileUtils;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Shaarli\Bookmark\BookmarkFilter;
use Shaarli\Security\SessionManager;
use Slim\Http\Request;
use Slim\Http\ServerRequest;
use Slim\Http\Response;

/**
Expand Down
Loading