-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathXBRL-ESMA-ESEF-Package.php
139 lines (118 loc) · 4.19 KB
/
XBRL-ESMA-ESEF-Package.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* XBRL ESMA Taxonomy Package handler
*
* @author Bill Seddon
* @version 0.9
* @Copyright (C) 2018 Lyquidity Solutions Limited
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Implements functions to read an ESMA taxonomy package
*/
class XBRL_ESMA_ESEF_Package extends XBRL_TaxonomyPackage
{
/**
* ESMA URL domain
* @var string
*/
private $url = "http://www.esma.europa.eu/";
/**
* Returns true if the zip file represents a package that meets the taxonomy package specification
* {@inheritDoc}
* @see XBRL_Package::isPackage()
*/
public function isPackage()
{
if ( ! parent::isPackage() ) return false;
$url = "http://www.esma.europa.eu/";
// If it is a package then is it an ESMA taxonomy package?
// It is if the publisher url is the ESMA url
if ( $this->publisherURL == $url ) return true;
// Or any one of the entry points starts with the url
foreach ( $this->getSchemaEntryPoints() as $entryPoint )
{
// if ( XBRL::startsWith( $entryPoint, $url ) ) return true;
}
// Now check the schema file to see if it references a recognized namespace
return $this->getIsExtensionTaxonomy();
}
/**
* Returns the name of the XBRL class that supports IFRS pckage contents
* {@inheritDoc}
* @see XBRL_Package::getXBRLClassname()
*/
public function getXBRLClassname()
{
return "XBRL_ESMA_ESEF";
}
/**
* Workout which file is the schema file
* @return void
* @throws "tpe:schemaFileNotFound"
*/
protected function determineSchemaFile()
{
if ( ! is_null( $this->schemaFile ) ) return;
$schemaFilesList = $this->getSchemaEntryPoints();
if ( count( $schemaFilesList ) == 0 )
{
throw XBRL_TaxonomyPackageException::withError( "tpe:schemaFileNotFound", "The package does not contain a schema (.xsd) file" );
}
foreach ( $schemaFilesList as $schemaFile )
{
if ( XBRL::startsWith( $schemaFile, 'http://www.esma.europa.eu/' ) &&
! XBRL::endsWith( $schemaFile, 'esef_cor.xsd' ) )
{
continue;
}
$actualUri = $this->getActualUri( $schemaFile );
$content = $this->getFile( $actualUri );
if ( $content )
{
$this->schemaNamespace = $this->getTargetNamespace( $schemaFile, $content );
$this->schemaFile = $schemaFile;
$this->setUrlMap();
}
break;
}
}
/**
* Can be implemented by concrete classes to return true if the taxonomy is an extension taxonomy
* This default implementation looks at the XBRL class name advertised by the class to determine
* if the schema file contains one of the entry points of the XBRL class.
* @param string $schemaFile
* @return bool
* @abstract
*/
protected function getIsExtensionTaxonomy( $schemaFile = null )
{
$this->determineSchemaFile();
if ( ! $schemaFile ) $schemaFile = $this->schemaFile;
// If the schema in the package imports one of the schemas with an entry point namespace then an extension compilation should be used
$xml = $this->getFileAsXML( $this->getActualUri( $schemaFile ) );
$xml->registerXPathNamespace( SCHEMA_PREFIX, SCHEMA_NAMESPACE );
foreach ( $xml->xpath("/xs:schema/xs:import") as $tag => /** @var SimpleXMLElement $element */ $element )
{
$attributes = $element->attributes();
if ( ! isset( $attributes['namespace'] ) ) continue;
// echo "{$attributes['namespace']}\n";
$nameOfXBRLClass = $this->getXBRLClassname();
if ( ( $className = $nameOfXBRLClass::class_from_namespace( (string)$attributes['namespace'] ) ) != $nameOfXBRLClass ) continue;
return true;
}
return false;
}
}