Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
URLReference | |
0.00% |
0 / 21 |
|
0.00% |
0 / 6 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
getStorageRow | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
fromStorageRow | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
toStorageRow | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getUrl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTargetIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Model; |
4 | |
5 | use Flow\Exception\InvalidReferenceException; |
6 | use MediaWiki\Title\Title; |
7 | |
8 | class URLReference extends Reference { |
9 | /** @var string */ |
10 | protected $url; |
11 | |
12 | /** |
13 | * @param UUID $id Id of the reference |
14 | * @param string $wiki Wiki ID of the reference source |
15 | * @param UUID $srcWorkflow ID of the source Workflow |
16 | * @param Title $srcTitle Title of the page that the Workflow exists on |
17 | * @param string $objectType Output of getRevisionType for the AbstractRevision that this reference comes from. |
18 | * @param UUID $objectId Unique identifier for the revisioned object containing the reference. |
19 | * @param string $type Type of reference |
20 | * @param string $url URL of the reference's target. |
21 | * @throws InvalidReferenceException |
22 | */ |
23 | public function __construct( UUID $id, $wiki, UUID $srcWorkflow, Title $srcTitle, $objectType, UUID $objectId, $type, $url ) { |
24 | $this->url = $url; |
25 | |
26 | if ( !is_array( wfParseUrl( $url ) ) ) { |
27 | throw new InvalidReferenceException( |
28 | "Invalid URL $url specified for reference " . get_class( $this ) |
29 | ); |
30 | } |
31 | |
32 | parent::__construct( $id, $wiki, $srcWorkflow, $srcTitle, $objectType, $objectId, $type ); |
33 | } |
34 | |
35 | /** |
36 | * Gets the storage row for this URLReference |
37 | * |
38 | * @return array |
39 | */ |
40 | public function getStorageRow() { |
41 | return parent::getStorageRow() + [ |
42 | 'ref_target' => $this->url, |
43 | ]; |
44 | } |
45 | |
46 | /** |
47 | * Instantiates a URLReference object from a storage row. |
48 | * |
49 | * @param array $row |
50 | * @return URLReference |
51 | */ |
52 | public static function fromStorageRow( $row ) { |
53 | // TODO: Remove this UUID::create() call when the field is populated |
54 | // everywhere relevant. |
55 | $id = isset( $row['ref_id'] ) ? UUID::create( $row['ref_id'] ) : UUID::create(); |
56 | $workflow = UUID::create( $row['ref_src_workflow_id'] ); |
57 | $objectType = $row['ref_src_object_type']; |
58 | $objectId = UUID::create( $row['ref_src_object_id'] ); |
59 | $url = $row['ref_target']; |
60 | $type = $row['ref_type']; |
61 | $srcTitle = Title::makeTitle( $row['ref_src_namespace'], $row['ref_src_title'] ); |
62 | $wiki = $row['ref_src_wiki']; |
63 | |
64 | return new URLReference( $id, $wiki, $workflow, $srcTitle, $objectType, $objectId, $type, $url ); |
65 | } |
66 | |
67 | /** |
68 | * Gets the storage row from an object. |
69 | * Helper for BasicObjectMapper. |
70 | * @param URLReference $object |
71 | * @return array |
72 | */ |
73 | public static function toStorageRow( URLReference $object ) { |
74 | return $object->getStorageRow(); |
75 | } |
76 | |
77 | public function getUrl() { |
78 | return $this->url; |
79 | } |
80 | |
81 | public function getTargetIdentifier() { |
82 | return 'url:' . $this->getUrl(); |
83 | } |
84 | } |