Skip to content

Commit 407387b

Browse files
committed
Xml::headerfields()
1 parent e563fa2 commit 407387b

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#`lib16/xml-builder-php`
22

3-
lib16 XML Builder is a PHP 7 library for creating XML documents.
3+
Some utility classes for lib16.
44

55
## Installation with Composer
66

@@ -31,26 +31,28 @@ class Kml extends Xml
3131
const FILENAME_EXTENSION = 'kml';
3232
const XML_NAMESPACE = 'http://www.opengis.net/kml/2.2';
3333

34-
public static function createKml()
34+
public static function createKml(): self
3535
{
3636
return static::createRoot('kml');
3737
}
3838

39-
public function placemark($name, $description, $longitude, $latitude, $altitude = 0)
39+
public function placemark(string $name, string $description,
40+
float $longitude, float $latitude, float $altitude = null): self
4041
{
4142
$pm = $this->append('Placemark');
4243
$pm->append('name', $name);
4344
$pm->append('description', $description);
44-
$pm->append('Point')
45-
->append('coordinates', $longitude . ',' . $latitude . ',' . $altitude);
45+
$pm->append('Point')->append('coordinates',
46+
implode(',', array_filter([$longitude, $latitude, $altitude])));
4647
return $pm;
4748
}
4849
}
4950

5051
$myKml = Kml::createKml();
51-
$myKml->placemark('Cologne Cathedral',
52+
$myKml->placemark(
53+
'Cologne Cathedral',
5254
'Cologne Cathedral is a Roman Catholic cathedral in Cologne, Germany.',
53-
'50.9413', '6.958');
55+
50.9413, 6.958);
5456
$myKml->headerfields('cologne-cathedral');
5557
print $myKml;
5658
```
@@ -64,7 +66,7 @@ The generated markup:
6466
<name>Cologne Cathedral</name>
6567
<description>Cologne Cathedral is a Roman Catholic cathedral in Cologne, Germany.</description>
6668
<Point>
67-
<coordinates>50.9413,6.958,0</coordinates>
69+
<coordinates>50.9413,6.958</coordinates>
6870
</Point>
6971
</Placemark>
7072
</kml>
@@ -89,7 +91,7 @@ class Html extends Xml
8991
const DOCTYPE = '<!DOCTYPE html>';
9092
const HTML_MODE_ENABLED = true;
9193

92-
public static function createHtml($lang = null, $manifest = null)
94+
public static function createHtml(string $lang = null, string $manifest = null): self
9395
{
9496
return static::createRoot('html')
9597
->attrib('lang', $lang)
@@ -123,3 +125,4 @@ The generated markup:
123125
</body>
124126
</html>
125127
```
128+

src/Xml.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ public static function getContentTypeHeaderfield()
300300
return 'Content-Type: ' . static::MIME_TYPE . '; charset=' . static::CHARACTER_ENCODING;
301301
}
302302

303+
public static function headerfields(string $filename = null)
304+
{
305+
if ($filename) {
306+
header(self::getContentDispositionHeaderfield($filename));
307+
}
308+
header(self::getContentTypeHeaderfield());
309+
}
310+
303311
private function isRoot(): bool
304312
{
305313
return $this->root == $this;

0 commit comments

Comments
 (0)