-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathLinkBase.php
76 lines (67 loc) · 2.16 KB
/
LinkBase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace adrianclay\xbrl\Taxonomy;
class LinkBase implements \IteratorAggregate {
/** @var Set */
private $set;
/** @var string */
private $path;
/** @var \DOMDocument */
private $dom;
/** @var ArcCollection[] */
private $links;
/**
* @param Set $set
* @param string $path
*/
public function __construct( Set $set, $path )
{
$this->set = $set;
$this->path = $path;
$this->dom = new \DOMDocument();
$this->dom->load( $path );
$xpath = new \DOMXPath( $this->dom );
$xpath->registerNamespace( 'link', 'http://www.xbrl.org/2003/linkbase' );
$xpath->registerNamespace( 'linkbase', 'http://www.xbrl.org/2003/linkbase' );
$lls = array();
/** @var $element \DOMElement */
foreach( $xpath->evaluate( '//link:linkbase/*' ) as $element ) {
switch( $element->nodeName ) {
case 'labelLink':
$lls[] = new Label\Link( $this, $element );
break;
case 'referenceLink':
$lls[] = new Reference\Link( $this, $element );
break;
case 'presentationLink':
$lls[] = new Presentation\Link( $this, $element );
break;
case 'calculationLink':
$lls[] = new Calculation\Link( $this, $element );
break;
case 'definitionLink':
$lls[] = new Definition\Link( $this, $element );
break;
}
}
$this->links = $lls;
}
/**
* Converts a string from "file.xsd#interestingElement" into a NamespaceId object
*
* @param string $href
* @return NamespaceId
*/
public function getConceptId( $href )
{
$parts = parse_url( $href );
$schema = $this->set->import( dirname( $this->path ), $parts['path'] );
return new NamespaceId( $schema->getNamespace(), $parts['fragment'] );
}
/**
* @return ArcCollection[]
*/
public function getIterator()
{
return new \ArrayIterator( $this->links );
}
}