summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
f24896b)
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
<?php
use Shaarli\Bookmark\LinkDB;
<?php
use Shaarli\Bookmark\LinkDB;
+use Shaarli\Bookmark\LinkFilter;
use Shaarli\Config\ConfigJson;
use Shaarli\Config\ConfigPhp;
use Shaarli\Config\ConfigManager;
use Shaarli\Config\ConfigJson;
use Shaarli\Config\ConfigPhp;
use Shaarli\Config\ConfigManager;
use Countable;
use DateTime;
use Iterator;
use Countable;
use DateTime;
use Iterator;
-use LinkFilter;
-use LinkNotFoundException;
+use Shaarli\Bookmark\LinkFilter;
+use Shaarli\Bookmark\Exception\LinkNotFoundException;
use Shaarli\Exceptions\IOException;
use Shaarli\FileUtils;
use Shaarli\Exceptions\IOException;
use Shaarli\FileUtils;
*
* Checks if the datastore exists; else, attempts to create a dummy one.
*
*
* Checks if the datastore exists; else, attempts to create a dummy one.
*
- * @param string $datastore datastore file path.
- * @param boolean $isLoggedIn is the user logged in?
- * @param boolean $hidePublicLinks if true all links are private.
- * @param string $redirector link redirector set in user settings.
+ * @param string $datastore datastore file path.
+ * @param boolean $isLoggedIn is the user logged in?
+ * @param boolean $hidePublicLinks if true all links are private.
+ * @param string $redirector link redirector set in user settings.
* @param boolean $redirectorEncode Enable urlencode on redirected urls (default: true).
*/
public function __construct(
* @param boolean $redirectorEncode Enable urlencode on redirected urls (default: true).
*/
public function __construct(
/**
* Filter links according to search parameters.
*
/**
* Filter links according to search parameters.
*
- * @param array $filterRequest Search request content. Supported keys:
+ * @param array $filterRequest Search request content. Supported keys:
* - searchtags: list of tags
* - searchterm: term search
* - searchtags: list of tags
* - searchterm: term search
- * @param bool $casesensitive Optional: Perform case sensitive filter
- * @param string $visibility return only all/private/public links
- * @param string $untaggedonly return only untagged links
+ * @param bool $casesensitive Optional: Perform case sensitive filter
+ * @param string $visibility return only all/private/public links
+ * @param bool $untaggedonly return only untagged links
*
* @return array filtered links, all links if no suitable filter was provided.
*/
*
* @return array filtered links, all links if no suitable filter was provided.
*/
/**
* Returns the list tags appearing in the links with the given tags
*
/**
* Returns the list tags appearing in the links with the given tags
*
- * @param array $filteringTags tags selecting the links to consider
- * @param string $visibility process only all/private/public links
+ * @param array $filteringTags tags selecting the links to consider
+ * @param string $visibility process only all/private/public links
*
* @return array tag => linksCount
*/
*
* @return array tag => linksCount
*/
* Rename or delete a tag across all links.
*
* @param string $from Tag to rename
* Rename or delete a tag across all links.
*
* @param string $from Tag to rename
- * @param string $to New tag. If none is provided, the from tag will be deleted
+ * @param string $to New tag. If none is provided, the from tag will be deleted
*
* @return array|bool List of altered links or false on error
*/
*
* @return array|bool List of altered links or false on error
*/
-use Shaarli\Bookmark\LinkDB;
+namespace Shaarli\Bookmark;
+
+use Exception;
+use Shaarli\Bookmark\Exception\LinkNotFoundException;
/**
* @var string permalinks.
*/
/**
* @var string permalinks.
*/
- public static $FILTER_HASH = 'permalink';
+ public static $FILTER_HASH = 'permalink';
/**
* @var string text search.
*/
/**
* @var string text search.
*/
- public static $FILTER_TEXT = 'fulltext';
+ public static $FILTER_TEXT = 'fulltext';
/**
* @var string tag filter.
*/
/**
* @var string tag filter.
*/
- public static $FILTER_TAG = 'tags';
+ public static $FILTER_TAG = 'tags';
/**
* @var string filter by day.
*/
/**
* @var string filter by day.
*/
- public static $FILTER_DAY = 'FILTER_DAY';
+ public static $FILTER_DAY = 'FILTER_DAY';
/**
* @var string Allowed characters for hashtags (regex syntax).
/**
* @var string Allowed characters for hashtags (regex syntax).
*/
public function filter($type, $request, $casesensitive = false, $visibility = 'all', $untaggedonly = false)
{
*/
public function filter($type, $request, $casesensitive = false, $visibility = 'all', $untaggedonly = false)
{
- if (! in_array($visibility, ['all', 'public', 'private'])) {
+ if (!in_array($visibility, ['all', 'public', 'private'])) {
foreach ($this->links as $key => $value) {
if ($value['private'] && $visibility === 'private') {
$out[$key] = $value;
foreach ($this->links as $key => $value) {
if ($value['private'] && $visibility === 'private') {
$out[$key] = $value;
- } elseif (! $value['private'] && $visibility === 'public') {
+ } elseif (!$value['private'] && $visibility === 'public') {
*
* @return array $filtered array containing permalink data.
*
*
* @return array $filtered array containing permalink data.
*
- * @throws LinkNotFoundException if the smallhash doesn't match any link.
+ * @throws \Shaarli\Bookmark\Exception\LinkNotFoundException if the smallhash doesn't match any link.
*/
private function filterSmallHash($smallHash)
{
*/
private function filterSmallHash($smallHash)
{
* - see https://github.com/shaarli/Shaarli/issues/75 for examples
*
* @param string $searchterms search query.
* - see https://github.com/shaarli/Shaarli/issues/75 for examples
*
* @param string $searchterms search query.
- * @param string $visibility Optional: return only all/private/public links.
+ * @param string $visibility Optional: return only all/private/public links.
*
* @return array search results.
*/
*
* @return array search results.
*/
foreach ($this->links as $id => $link) {
// ignore non private links when 'privatonly' is on.
if ($visibility !== 'all') {
foreach ($this->links as $id => $link) {
// ignore non private links when 'privatonly' is on.
if ($visibility !== 'all') {
- if (! $link['private'] && $visibility === 'private') {
+ if (!$link['private'] && $visibility === 'private') {
continue;
} elseif ($link['private'] && $visibility === 'public') {
continue;
continue;
} elseif ($link['private'] && $visibility === 'public') {
continue;
/**
* generate a regex fragment out of a tag
/**
* generate a regex fragment out of a tag
* @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard
* @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard
* @return string generated regex fragment
*/
private static function tag2regex($tag)
* @return string generated regex fragment
*/
private static function tag2regex($tag)
// check level of visibility
// ignore non private links when 'privateonly' is on.
if ($visibility !== 'all') {
// check level of visibility
// ignore non private links when 'privateonly' is on.
if ($visibility !== 'all') {
- if (! $link['private'] && $visibility === 'private') {
+ if (!$link['private'] && $visibility === 'private') {
continue;
} elseif ($link['private'] && $visibility === 'public') {
continue;
continue;
} elseif ($link['private'] && $visibility === 'public') {
continue;
$filtered = [];
foreach ($this->links as $key => $link) {
if ($visibility !== 'all') {
$filtered = [];
foreach ($this->links as $key => $link) {
if ($visibility !== 'all') {
- if (! $link['private'] && $visibility === 'private') {
+ if (!$link['private'] && $visibility === 'private') {
continue;
} elseif ($link['private'] && $visibility === 'public') {
continue;
continue;
} elseif ($link['private'] && $visibility === 'public') {
continue;
*/
public function filterDay($day)
{
*/
public function filterDay($day)
{
- if (! checkDateFormat('Ymd', $day)) {
+ if (!checkDateFormat('Ymd', $day)) {
throw new Exception('Invalid date format');
}
throw new Exception('Invalid date format');
}
return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY);
}
}
return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY);
}
}
-
-class LinkNotFoundException extends Exception
-{
- /**
- * LinkNotFoundException constructor.
- */
- public function __construct()
- {
- $this->message = t('The link you are trying to reach does not exist or has been deleted.');
- }
-}
--- /dev/null
+<?php
+namespace Shaarli\Bookmark\Exception;
+
+use Exception;
+
+class LinkNotFoundException extends Exception
+{
+ /**
+ * LinkNotFoundException constructor.
+ */
+ public function __construct()
+ {
+ $this->message = t('The link you are trying to reach does not exist or has been deleted.');
+ }
+}
"Shaarli\\Api\\Controllers\\": "application/api/controllers",
"Shaarli\\Api\\Exceptions\\": "application/api/exceptions",
"Shaarli\\Bookmark\\": "application/bookmark",
"Shaarli\\Api\\Controllers\\": "application/api/controllers",
"Shaarli\\Api\\Exceptions\\": "application/api/exceptions",
"Shaarli\\Bookmark\\": "application/bookmark",
+ "Shaarli\\Bookmark\\Exception\\": "application/bookmark/exception",
"Shaarli\\Config\\": "application/config/",
"Shaarli\\Config\\Exception\\": "application/config/exception",
"Shaarli\\Exceptions\\": "application/exceptions",
"Shaarli\\Config\\": "application/config/",
"Shaarli\\Config\\Exception\\": "application/config/exception",
"Shaarli\\Exceptions\\": "application/exceptions",
require_once 'application/http/UrlUtils.php';
require_once 'application/FileUtils.php';
require_once 'application/History.php';
require_once 'application/http/UrlUtils.php';
require_once 'application/FileUtils.php';
require_once 'application/History.php';
-require_once 'application/LinkFilter.php';
require_once 'application/LinkUtils.php';
require_once 'application/NetscapeBookmarkUtils.php';
require_once 'application/TimeZone.php';
require_once 'application/LinkUtils.php';
require_once 'application/NetscapeBookmarkUtils.php';
require_once 'application/TimeZone.php';
require_once 'application/Router.php';
require_once 'application/Updater.php';
require_once 'application/Router.php';
require_once 'application/Updater.php';
+use \Shaarli\Bookmark\Exception\LinkNotFoundException;
use \Shaarli\Bookmark\LinkDB;
use \Shaarli\Config\ConfigManager;
use \Shaarli\Feed\CachedPage;
use \Shaarli\Bookmark\LinkDB;
use \Shaarli\Config\ConfigManager;
use \Shaarli\Feed\CachedPage;
namespace Shaarli\Bookmark;
use DateTime;
namespace Shaarli\Bookmark;
use DateTime;
-use LinkNotFoundException;
+use Shaarli\Bookmark\Exception\LinkNotFoundException;
use ReferenceLinkDB;
use ReflectionClass;
use Shaarli;
use ReferenceLinkDB;
use ReflectionClass;
use Shaarli;
/**
* Test filterHash() with an invalid smallhash.
*
/**
* Test filterHash() with an invalid smallhash.
*
- * @expectedException LinkNotFoundException
+ * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
*/
public function testFilterHashInValid1()
{
*/
public function testFilterHashInValid1()
{
/**
* Test filterHash() with an empty smallhash.
*
/**
* Test filterHash() with an empty smallhash.
*
- * @expectedException LinkNotFoundException
+ * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
*/
public function testFilterHashInValid()
{
*/
public function testFilterHashInValid()
{
-use Shaarli\Bookmark\LinkDB;
+namespace Shaarli\Bookmark;
-require_once 'application/LinkFilter.php';
+use Exception;
+use ReferenceLinkDB;
/**
* Class LinkFilterTest.
*/
/**
* Class LinkFilterTest.
*/
-class LinkFilterTest extends PHPUnit_Framework_TestCase
+class LinkFilterTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string Test datastore path.
{
/**
* @var string Test datastore path.
protected static $linkDB;
/**
protected static $linkDB;
/**
- * Instanciate linkFilter with ReferenceLinkDB data.
+ * Instantiate linkFilter with ReferenceLinkDB data.
*/
public static function setUpBeforeClass()
{
*/
public static function setUpBeforeClass()
{
count(
self::$linkFilter->filter(
LinkFilter::$FILTER_TAG,
count(
self::$linkFilter->filter(
LinkFilter::$FILTER_TAG,
- /*$request=*/'',
- /*$casesensitive=*/false,
- /*$visibility=*/'all',
- /*$untaggedonly=*/true
+ /*$request=*/
+ '',
+ /*$casesensitive=*/
+ false,
+ /*$visibility=*/
+ 'all',
+ /*$untaggedonly=*/
+ true
/**
* No link for this hash
*
/**
* No link for this hash
*
- * @expectedException LinkNotFoundException
+ * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
*/
public function testFilterUnknownSmallHash()
{
*/
public function testFilterUnknownSmallHash()
{