Skip to content

Commit 01455a1

Browse files
committed
fixing bug in filename while using PHP's double-quoted string interpolation feature
1 parent 4321985 commit 01455a1

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

DCAT.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function makeDataBlob(){
1919
$langs = array ();
2020
foreach ( scandir( 'i18n' ) as $key => $filename ) {
2121
if ( substr( $filename, -strlen( '.json' ) ) === '.json' && $filename !== 'qqq.json' ) {
22-
$langs[substr( $filename, 0, -strlen( '.json' ) )] = 'i18n/'.$filename;
22+
$langs[substr( $filename, 0, -strlen( '.json' ) )] = "i18n/$filename";
2323
}
2424
}
2525

@@ -32,11 +32,11 @@ function makeDataBlob(){
3232
// load catalog i18n info from URL and add to i18n object
3333
$i18nJSON = json_decode( file_get_contents( $config['catalog-info'] ), true );
3434
foreach ( array_keys( $i18n ) as $langCode ) {
35-
if ( array_key_exists( $langCode.'-title', $i18nJSON ) ) {
36-
$i18n[$langCode]['catalog-title'] = $i18nJSON[$langCode.'-title'];
35+
if ( array_key_exists( "$langCode-title", $i18nJSON ) ) {
36+
$i18n[$langCode]['catalog-title'] = $i18nJSON["$langCode-title"];
3737
}
38-
if ( array_key_exists( $langCode.'-description', $i18nJSON ) ) {
39-
$i18n[$langCode]['catalog-description'] = $i18nJSON[$langCode.'-description'];
38+
if ( array_key_exists( "$langCode-description", $i18nJSON ) ) {
39+
$i18n[$langCode]['catalog-description'] = $i18nJSON["$langCode-description"];
4040
}
4141
}
4242

@@ -70,7 +70,7 @@ function makeDataBlob(){
7070
* @param string $dumpDate: the date of the dumpfile, null for live data
7171
*/
7272
function dumpDistributionExtras(XMLWriter $xml, $data, $dumpDate){
73-
$url = str_replace( '$1', $dumpDate.'json.gz', $data['config']['dump-info']['accessURL'] );
73+
$url = str_replace( '$1', "$dumpDate.json.gz", $data['config']['dump-info']['accessURL'] );
7474

7575
$xml->startElementNS( 'dcat', 'accessURL', null );
7676
$xml->writeAttributeNS( 'rdf', 'resource', null, $url );
@@ -101,7 +101,7 @@ function dumpDistributionExtras(XMLWriter $xml, $data, $dumpDate){
101101
function writeDistribution(XMLWriter $xml, $data, $distribId, $prefix, $dumpDate){
102102
$ids = array ();
103103

104-
foreach ( $data['config'][$prefix.'-info']['mediatype'] as $format => $mediatype ) {
104+
foreach ( $data['config']["$prefix-info"]['mediatype'] as $format => $mediatype ) {
105105
$id = $data['config']['uri'].'#'.$distribId.$dumpDate.$format;
106106
array_push( $ids, $id );
107107

@@ -113,12 +113,12 @@ function writeDistribution(XMLWriter $xml, $data, $distribId, $prefix, $dumpDate
113113
$xml->endElement();
114114

115115
$xml->startElementNS( 'dcterms', 'license', null );
116-
$xml->writeAttributeNS( 'rdf', 'resource', null, $data['config'][$prefix.'-info']['license'] );
116+
$xml->writeAttributeNS( 'rdf', 'resource', null, $data['config']["$prefix-info"]['license'] );
117117
$xml->endElement();
118118

119119
if ( is_null( $dumpDate ) ) {
120120
$xml->startElementNS( 'dcat', 'accessURL', null );
121-
$xml->writeAttributeNS( 'rdf', 'resource', null, $data['config'][$prefix.'-info']['accessURL'] );
121+
$xml->writeAttributeNS( 'rdf', 'resource', null, $data['config']["$prefix-info"]['accessURL'] );
122122
$xml->endElement();
123123
}
124124
else {
@@ -129,10 +129,10 @@ function writeDistribution(XMLWriter $xml, $data, $distribId, $prefix, $dumpDate
129129

130130
// add description in each language
131131
foreach ( $data['i18n'] as $langCode => $langData ) {
132-
if ( array_key_exists( 'distribution-'.$prefix.'-description', $langData ) ) {
132+
if ( array_key_exists( "distribution-$prefix-description", $langData ) ) {
133133
$xml->startElementNS( 'dcterms', 'description', null );
134134
$xml->writeAttributeNS( 'xml', 'lang', null, $langCode );
135-
$xml->text( $langData['distribution-'.$prefix.'-description'] );
135+
$xml->text( $langData["distribution-$prefix-description"] );
136136
$xml->endElement();
137137
}
138138
}
@@ -190,13 +190,13 @@ function writeDataset(XMLWriter $xml, $data, $dumpDate, $datasetId, $publisher,
190190
// add themes
191191
foreach ( $data['config']['themes'] as $key => $keyword ) {
192192
$xml->startElementNS( 'dcat', 'theme', null );
193-
$xml->writeAttributeNS( 'rdf', 'resource', null, 'http://eurovoc.europa.eu/'.$keyword );
193+
$xml->writeAttributeNS( 'rdf', 'resource', null, "http://eurovoc.europa.eu/$keyword" );
194194
$xml->endElement();
195195
}
196196

197197
// add title and description in each language
198198
foreach ( $data['i18n'] as $langCode => $langData ) {
199-
if ( array_key_exists( 'dataset-'.$type.'-title', $langData ) ) {
199+
if ( array_key_exists( "dataset-$type-title", $langData ) ) {
200200
$xml->startElementNS( 'dcterms', 'title', null );
201201
$xml->writeAttributeNS( 'xml', 'lang', null, $langCode );
202202
if ( $type === 'live' ) {
@@ -209,10 +209,10 @@ function writeDataset(XMLWriter $xml, $data, $dumpDate, $datasetId, $publisher,
209209
}
210210
$xml->endElement();
211211
}
212-
if ( array_key_exists( 'dataset-'.$type.'-description', $langData ) ) {
212+
if ( array_key_exists( "dataset-$type-description", $langData ) ) {
213213
$xml->startElementNS( 'dcterms', 'description', null );
214214
$xml->writeAttributeNS( 'xml', 'lang', null, $langCode );
215-
$xml->text( $langData['dataset-'.$type.'-description'] );
215+
$xml->text( $langData["dataset-$type-description"] );
216216
$xml->endElement();
217217
}
218218
}
@@ -314,7 +314,7 @@ function writeCatalog(XMLWriter $xml, $data, $publisher, $dataset){
314314
// add language, title and description in each language
315315
foreach ( $data['i18n'] as $langCode => $langData ) {
316316
$xml->startElementNS( 'dcterms', 'language', null );
317-
$xml->writeAttributeNS( 'rdf', 'resource', null, 'http://id.loc.gov/vocabulary/iso639-1/'.$langCode );
317+
$xml->writeAttributeNS( 'rdf', 'resource', null, "http://id.loc.gov/vocabulary/iso639-1/$langCode" );
318318
$xml->endElement();
319319

320320
if ( array_key_exists( 'catalog-title', $langData ) ) {
@@ -413,7 +413,7 @@ function scanDump($dirname){
413413

414414
foreach ( scandir( $dirname ) as $key => $filename ) {
415415
if ( substr( $filename, -strlen( $teststring ) ) === $teststring ) {
416-
$info = stat( $dirname.'/'.$filename );
416+
$info = stat( "$dirname/$filename" );
417417
$dumps[substr( $filename, 0, -strlen( $teststring ) )] = array (
418418
'timestamp' => gmdate( 'Y-m-d\TH:i:s', $info['mtime'] ),
419419
'byteSize' => $info['size']
@@ -440,7 +440,7 @@ function run($directory=null){
440440

441441
// test if dir exists
442442
if ( !is_dir( $directory ) ) {
443-
echo $directory.' is not a valid directory';
443+
echo "$directory is not a valid directory";
444444
return;
445445
}
446446

@@ -450,6 +450,6 @@ function run($directory=null){
450450
// create xml string from data blob
451451
$xml = outputXml( $data );
452452

453-
file_put_contents( $directory.'/dcatap.rdf', $xml );
453+
file_put_contents( "$directory/dcatap.rdf", $xml );
454454
}
455455
?>

0 commit comments

Comments
 (0)