public function addFeed($url)
{
$r = $this->setupRequest($url);
- $r->send();
- $this->handleResponse($r);
+ $r->send();
+ $this->handleResponse($r);
}
public function addFeeds($urls)
protected function saveFeed($file, $contents)
{
- if (file_put_contents($this->directory .'/'. $file .'.xml', $contents)) {
- $this->feeds[$file] = time();
- } else {
- throw new Exception("Could not save feed contents to $file.xml");
- }
+ if (file_put_contents($this->directory .'/'. $file .'.xml', $contents)) {
+ $this->feeds[$file] = time();
+ } else {
+ throw new Exception("Could not save feed contents to $file.xml");
+ }
}
protected function loadFeed($file)
protected function setupRequest($url)
{
- $r = new HttpRequest($url);
- $r->setOptions(array('redirect' => true));
+ $r = new HttpRequest($url);
+ $r->setOptions(array('redirect' => true));
$file = $this->url2name($url);
protected function handleResponse(HttpRequest $r)
{
if ($r->getResponseCode() != 304) {
- if ($r->getResponseCode() != 200) {
- throw new Exception("Unexpected response code ". $r->getResponseCode());
- }
- if (!strlen($body = $r->getResponseBody())) {
- throw new Exception("Received empty feed from ". $r->getUrl());
- }
- $this->saveFeed($file, $body);
- }
+ if ($r->getResponseCode() != 200) {
+ throw new Exception("Unexpected response code ". $r->getResponseCode());
+ }
+ if (!strlen($body = $r->getResponseBody())) {
+ throw new Exception("Received empty feed from ". $r->getUrl());
+ }
+ $this->saveFeed($file, $body);
+ }
}
}
?>
<?php
+/**
+ * extract examples from tutorial.txt
+ */
if (preg_match_all('/\n- ([^\n]+).*?(\<\?.+?\?\>)/s', file_get_contents($_SERVER['argv'][1]), $matches)) {
for ($i = 0; $i < count($matches[0]); $i++) {
public function addFeed($url)
{
$r = $this->setupRequest($url);
- $r->send();
- $this->handleResponse($r);
+ $r->send();
+ $this->handleResponse($r);
}
public function addFeeds($urls)
protected function saveFeed($file, $contents)
{
- if (file_put_contents($this->directory .'/'. $file .'.xml', $contents)) {
- $this->feeds[$file] = time();
- } else {
- throw new Exception("Could not save feed contents to $file.xml");
- }
+ if (file_put_contents($this->directory .'/'. $file .'.xml', $contents)) {
+ $this->feeds[$file] = time();
+ } else {
+ throw new Exception("Could not save feed contents to $file.xml");
+ }
}
protected function loadFeed($file)
protected function setupRequest($url)
{
- $r = new HttpRequest($url);
- $r->setOptions(array('redirect' => true));
+ $r = new HttpRequest($url);
+ $r->setOptions(array('redirect' => true));
$file = $this->url2name($url);
protected function handleResponse(HttpRequest $r)
{
if ($r->getResponseCode() != 304) {
- if ($r->getResponseCode() != 200) {
- throw new Exception("Unexpected response code ". $r->getResponseCode());
- }
- if (!strlen($body = $r->getResponseBody())) {
- throw new Exception("Received empty feed from ". $r->getUrl());
- }
- $this->saveFeed($file, $body);
- }
+ if ($r->getResponseCode() != 200) {
+ throw new Exception("Unexpected response code ". $r->getResponseCode());
+ }
+ if (!strlen($body = $r->getResponseBody())) {
+ throw new Exception("Received empty feed from ". $r->getUrl());
+ }
+ $this->saveFeed($file, $body);
+ }
}
}
?>