Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added XML_KML_Common, extended _Place,_Style, fixed up XML_KML_Create
  • Loading branch information
till authored and hamstar committed Oct 18, 2009
1 parent 89b038d commit fb16949
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 59 deletions.
44 changes: 44 additions & 0 deletions XML/KML/Common.php
@@ -0,0 +1,44 @@
<?php

/**
* Create a KML file
*
* Class for creating a KML file from a data source
* and outputing it to either a file or string
*
* PHP version 5
*
* @category XML
* @package Create_KML
* @author Robert McLeod <hamstar@telescum.co.nz>
* @copyright 2009 Robert McLeod
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version SVN: 1.0
* @link ??
*
*/

/**
* Class to define a style to be added to the KML class
*
* @category XML
* @package Create_KML
* @author Robert McLeod <hamstar@telescum.co.nz>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link ??
*/
class XML_KML_Common
{
/**
* Destructor
*
*/
function __destruct()
{
// Destory all values
foreach ($this as &$v) {
$v = null;
}
}
}
?>
21 changes: 7 additions & 14 deletions XML/KML/Create.php
Expand Up @@ -18,6 +18,7 @@
*
*/

require 'XML/KML/Exception.php';
require 'XML/KML/Place.php';
require 'XML/KML/Style.php';

Expand Down Expand Up @@ -87,20 +88,13 @@ public function printHeader($xml = false)
/**
* Adds an item to the KML data
*
* @param object $item The object to add
* @param XML_KML_Common $item The object to add
*
* @return boolean
* @return $this
* @throws XML_KML_Exception When you inject something we don't know about.
*/
public function addItem($item)
public function addItem(XML_KML_Common $item)
{
if (!$item
|| !is_object($item)
|| $item->type != 'style'
&& $item->type != 'place'
) {
return false;
}

// Switch which array to put the given item in
switch ($item->type) {
case 'place':
Expand All @@ -112,10 +106,9 @@ public function addItem($item)
break;

default:
return false;
break;
throw new XML_KML_Exception("Unsupported object.");
}
return true;
return $this;
}

/**
Expand Down
23 changes: 2 additions & 21 deletions XML/KML/Place.php
Expand Up @@ -19,6 +19,7 @@
*/

require_once 'XML/KML/Exception.php';
require_once 'XML/KML/Common.php';

/**
* Class to define a place to be added to the KML class
Expand All @@ -29,32 +30,12 @@
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link ??
*/
class XML_KML_Place
class XML_KML_Place extends XML_KML_Common
{
protected $type = 'place';
protected $folder = '**[root]**';
protected $id, $name, $desc, $style, $coords;

/**
* Constructor
*
*/
public function __construct()
{
}

/**
* Destructor
*
*/
public function __destruct()
{
// Destory all values
foreach ($this as &$v) {
$v = null;
}
}

/**
* Encloses a string in CDATA escaping if it
* contains html tags
Expand Down
32 changes: 8 additions & 24 deletions XML/KML/Style.php
Expand Up @@ -18,6 +18,8 @@
*
*/

require_once 'XML/KML/Common.php';

/**
* Class to define a style to be added to the KML class
*
Expand All @@ -27,30 +29,11 @@
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link ??
*/
class XML_KML_Style
class XML_KML_Style extends XML_KML_Common
{
/**
* Constructor
*
*/
function __construct()
{
protected $type = 'style';
protected $id, $iconid, $iconhref;
}

/**
* Destructor
*
*/
function __destruct()
{
// Destory all values
foreach ($this as &$v) {
$v = null;
}
}

protected $type = 'style';
protected $id, $iconid, $iconhref;

/**
* Sets the id, stripping tags
*
Expand Down Expand Up @@ -81,6 +64,7 @@ public function setIconId($id)
* @param string $href Link to the icon for the style
*
* @return void
* @throws XML_KML_Exception When an invalid URL is provided.
*/
public function setIconLink($href)
{
Expand All @@ -89,7 +73,7 @@ public function setIconLink($href)
}

// Not a valid URL
return false;
throw new XML_KML_Exception("Invalid URL.");
}
}

Expand Down

0 comments on commit fb16949

Please sign in to comment.