public static function parse_list($response) { $result = array(); try { $atom = Atom::parse($response, new YouTubeDataMedia()); } catch (Exception $e) { throw new Exception($response); } foreach ($atom->arEntry() as $entry) { $obj = new self(); $links = $entry->link(); if (isset($links[0])) { $obj->url($links[0]->href()); } if (isset($links[3])) { $obj->mobile_url($links[3]->href()); } if ($entry->content() instanceof AtomContent) { $obj->content($entry->content()->value()); } $obj->title($entry->title()); $obj->published($entry->published()); $obj->updated($entry->updated()); $obj->keyword($entry->extra()->keyword()); $obj->duration($entry->extra()->duration()); $obj->player($entry->extra()->player()); $obj->category($entry->extra()->category()); $obj->thumbnail($entry->extra()->thumbnail()); $result[] = $obj; } return $result; }
/** * フィードを取得 * * @param string $src * @return Atom */ public static function parse($src) { try { return Atom::parse($src); } catch (Exception $e) { try { return Rss::parse($src)->atom(); } catch (Exception $e) { try { return Opml::parse($src)->atom(); } catch (Exception $e) { throw new Exception("no feed"); } } } /*** $src = text(' <feed xmlns="http://www.w3.org/2005/Atom"> <title>atom10 feed</title> <subtitle>atom10 sub title</subtitle> <updated>2007-07-18T16:16:31+00:00</updated> <generator>tokushima</generator> <link href="http://tokushimakazutaka.com" rel="abc" type="xyz" /> <author> <url>http://tokushimakazutaka.com</url> <name>tokushima</name> <email>tokushima@hoge.hoge</email> </author> <entry> <title>rhaco</title> <summary type="xml" xml:lang="ja">summary test</summary> <content type="text/xml" mode="abc" xml:lang="ja" xml:base="base">atom content</content> <link href="http://rhaco.org" rel="abc" type="xyz" /> <link href="http://conveyor.rhaco.org" rel="abc" type="conveyor" /> <link href="http://lib.rhaco.org" rel="abc" type="lib" /> <updated>2007-07-18T16:16:31+00:00</updated> <issued>2007-07-18T16:16:31+00:00</issued> <published>2007-07-18T16:16:31+00:00</published> <id>rhaco</id> <author> <url>http://rhaco.org</url> <name>rhaco</name> <email>rhaco@rhaco.org</email> </author> </entry> <entry> <title>django</title> <summary type="xml" xml:lang="ja">summary test</summary> <content type="text/xml" mode="abc" xml:lang="ja" xml:base="base">atom content</content> <link href="http://djangoproject.jp" rel="abc" type="xyz" /> <updated>2007-07-18T16:16:31+00:00</updated> <issued>2007-07-18T16:16:31+00:00</issued> <published>2007-07-18T16:16:31+00:00</published> <id>django</id> <author> <url>http://www.everes.net</url> <name>everes</name> <email>everes@hoge.hoge</email> </author> </entry> </feed> '); $xml = Feed::parse($src); $result = text(' <feed xmlns="http://www.w3.org/2005/Atom"> <title>atom10 feed</title> <subtitle>atom10 sub title</subtitle> <id>rhaco</id> <generator>tokushima</generator> <updated>2007-07-18T16:16:31Z</updated> <link rel="abc" type="xyz" href="http://tokushimakazutaka.com" /> <entry> <id>rhaco</id> <title>rhaco</title> <published>2007-07-18T16:16:31Z</published> <updated>2007-07-18T16:16:31Z</updated> <issued>2007-07-18T16:16:31Z</issued> <content type="text/xml" mode="abc" xml:lang="ja" xml:base="base">atom content</content> <summary type="xml" xml:lang="ja">summary test</summary> <link rel="abc" type="xyz" href="http://rhaco.org" /> <link rel="abc" type="conveyor" href="http://conveyor.rhaco.org" /> <link rel="abc" type="lib" href="http://lib.rhaco.org" /> <author> <name>rhaco</name> <url>http://rhaco.org</url> <email>rhaco@rhaco.org</email> </author> </entry> <entry> <id>django</id> <title>django</title> <published>2007-07-18T16:16:31Z</published> <updated>2007-07-18T16:16:31Z</updated> <issued>2007-07-18T16:16:31Z</issued> <content type="text/xml" mode="abc" xml:lang="ja" xml:base="base">atom content</content> <summary type="xml" xml:lang="ja">summary test</summary> <link rel="abc" type="xyz" href="http://djangoproject.jp" /> <author> <name>everes</name> <url>http://www.everes.net</url> <email>everes@hoge.hoge</email> </author> </entry> <author> <name>tokushima</name> <url>http://tokushimakazutaka.com</url> <email>tokushima@hoge.hoge</email> </author> </feed> '); $result = str_replace(array("\n","\t"),"",$result); eq($result,(string)$xml); */ }