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:
<?php
namespace Coast;
use Coast\Xml;
use Coast\Model;
use Coast\Collection;
class Sitemap extends Model
{
protected $urls;
protected static function _metadataStaticBuild()
{
return parent::_metadataStaticBuild()
->properties([
'urls' => [
'type' => Model::TYPE_MANY,
'isConstruct' => true,
'isTraverse' => true,
'construct' => 'Coast\Sitemap\Url',
],
]);
}
public function __construct()
{
$this->urls = new Collection();
}
public function toXml()
{
$xml = new Xml('<?xml version="1.0" encoding="UTF-8"?><urlset/>');
$xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
foreach ($this->urls as $url) {
$xml->appendChild($url->toXml());
}
return $xml;
}
}