123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?php
- require_once 'XML/XRD/PropertyAccess.php';
- require_once 'XML/XRD/Element/Link.php';
- require_once 'XML/XRD/Loader.php';
- require_once 'XML/XRD/Serializer.php';
- class XML_XRD extends XML_XRD_PropertyAccess implements IteratorAggregate
- {
-
- public $loader;
-
- public $serializer;
-
- public $subject;
-
- public $aliases = array();
-
- public $links = array();
-
- public $expires;
-
- public $id;
-
- public function loadFile($file, $type = null)
- {
- if (!isset($this->loader)) {
- $this->loader = new XML_XRD_Loader($this);
- }
- return $this->loader->loadFile($file, $type);
- }
-
- public function loadString($str, $type = null)
- {
- if (!isset($this->loader)) {
- $this->loader = new XML_XRD_Loader($this);
- }
- return $this->loader->loadString($str, $type);
- }
-
- public function describes($uri)
- {
- if ($this->subject == $uri) {
- return true;
- }
- foreach ($this->aliases as $alias) {
- if ($alias == $uri) {
- return true;
- }
- }
- return false;
- }
-
- public function get($rel, $type = null, $typeFallback = true)
- {
- $links = $this->getAll($rel, $type, $typeFallback);
- if (count($links) == 0) {
- return null;
- }
- return $links[0];
- }
-
- public function getAll($rel, $type = null, $typeFallback = true)
- {
- $links = array();
- $exactType = false;
- foreach ($this->links as $link) {
- if ($link->rel == $rel
- && ($type === null || $link->type == $type
- || $typeFallback && $link->type === null)
- ) {
- $links[] = $link;
- $exactType |= $typeFallback && $type !== null
- && $link->type == $type;
- }
- }
- if ($exactType) {
-
- $exactlinks = array();
- foreach ($links as $link) {
- if ($link->type !== null) {
- $exactlinks[] = $link;
- }
- }
- $links = $exactlinks;
- }
- return $links;
- }
-
- public function getIterator()
- {
- return new ArrayIterator($this->links);
- }
-
- public function to($type)
- {
- if (!isset($this->serializer)) {
- $this->serializer = new XML_XRD_Serializer($this);
- }
- return $this->serializer->to($type);
- }
-
- public function toXML()
- {
- return $this->to('xml');
- }
- }
- ?>
|