Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20namespace MediaWiki\Linker;
21
22use RuntimeException;
23use stdClass;
24use Wikimedia\Rdbms\IDatabase;
25
26/**
27 * @since 1.38
28 */
29interface LinkTargetLookup {
30    /**
31     * Instantiate a new LinkTarget object based on a $row from the linktarget table.
32     *
33     * Use this method when a linktarget row was already fetched from the DB via a join.
34     * This method just constructs a new instance and does not try fetching missing
35     * values from the DB again.
36     *
37     * @param stdClass $row with the following fields:
38     *  - int lt_id
39     *  - int lt_namespace
40     *  - string lt_title
41     * @return LinkTarget
42     */
43    public function newLinkTargetFromRow( stdClass $row ): LinkTarget;
44
45    /**
46     * Find a link target by $id.
47     *
48     * @param int $linkTargetId
49     * @return LinkTarget|null Returns null if no link target with this $linkTargetId exists in the database.
50     */
51    public function getLinkTargetById( int $linkTargetId ): ?LinkTarget;
52
53    /**
54     * Attempt to assign an link target ID to the given $linkTarget. If it is already assigned,
55     * return the existing ID.
56     *
57     * @note If called within a transaction, the returned ID might become invalid
58     * if the transaction is rolled back, so it should not be passed outside of the
59     * transaction context.
60     *
61     * @param LinkTarget $linkTarget
62     * @param IDatabase $dbw The database connection to acquire the ID from.
63     * @return int linktarget ID greater then 0
64     * @throws RuntimeException if no linktarget ID has been assigned to this $linkTarget
65     */
66    public function acquireLinkTargetId( LinkTarget $linkTarget, IDatabase $dbw ): int;
67
68    /**
69     * Return link target id if exists
70     *
71     * @param LinkTarget $linkTarget
72     * @return int|null linktarget ID greater then 0, null if not found
73     */
74    public function getLinkTargetId( LinkTarget $linkTarget ): ?int;
75
76}