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