[ticket/13713] Create source interface

PHPBB3-13713
This commit is contained in:
lavigor 2018-05-18 16:33:55 +03:00 committed by Marc Alexander
parent b6e2d1f48c
commit f6c9f4fb13
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
4 changed files with 44 additions and 1 deletions

View file

@ -32,6 +32,9 @@ class friend extends user
parent::__construct($db); parent::__construct($db);
} }
/**
* {@inheritdoc}
*/
protected function query($keyword, $topic_id) protected function query($keyword, $topic_id)
{ {
$query = $this->db->sql_build_query('SELECT', [ $query = $this->db->sql_build_query('SELECT', [

View file

@ -0,0 +1,27 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\mention\source;
interface source_interface
{
/**
* Searches database for names to mention
* and returns and array of found items
*
* @param string $keyword Search string
* @param int $topic_id Current topic ID
* @return array Array of names
*/
public function get($keyword, $topic_id);
}

View file

@ -15,6 +15,9 @@ namespace phpbb\mention\source;
class topic extends user class topic extends user
{ {
/**
* {@inheritdoc}
*/
protected function query($keyword, $topic_id) protected function query($keyword, $topic_id)
{ {
$query = $this->db->sql_build_query('SELECT', [ $query = $this->db->sql_build_query('SELECT', [

View file

@ -13,7 +13,7 @@
namespace phpbb\mention\source; namespace phpbb\mention\source;
abstract class user abstract class user implements source_interface
{ {
/** @var \phpbb\db\driver\driver_interface */ /** @var \phpbb\db\driver\driver_interface */
protected $db; protected $db;
@ -26,8 +26,18 @@ abstract class user
$this->db = $db; $this->db = $db;
} }
/**
* Builds a query based on user input
*
* @param string $keyword Search string
* @param int $topic_id Current topic ID
* @return string Query ready for execution
*/
abstract protected function query($keyword, $topic_id); abstract protected function query($keyword, $topic_id);
/**
* {@inheritdoc}
*/
public function get($keyword, $topic_id) public function get($keyword, $topic_id)
{ {
$keyword = utf8_clean_string($keyword); $keyword = utf8_clean_string($keyword);