- ws
authorMichael Wallner <mike@php.net>
Mon, 12 Sep 2005 12:36:51 +0000 (12:36 +0000)
committerMichael Wallner <mike@php.net>
Mon, 12 Sep 2005 12:36:51 +0000 (12:36 +0000)
docs/examples/Simple_Feed_Aggregator.php
docs/examples/extract.php
docs/examples/tutorial.txt

index f82e31675be71a89e28bf26122709617a1392bd7..fd7ade47e17ce4b6ba4c9529d6441d5162bd4ec8 100644 (file)
@@ -30,8 +30,8 @@ class FeedAggregator
        public function addFeed($url)
        {
                $r = $this->setupRequest($url);
-        $r->send();
-        $this->handleResponse($r);
+               $r->send();
+               $this->handleResponse($r);
        }
 
        public function addFeeds($urls)
@@ -65,11 +65,11 @@ class FeedAggregator
 
        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)
@@ -87,8 +87,8 @@ class FeedAggregator
 
        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);
 
@@ -102,14 +102,14 @@ class FeedAggregator
        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);
+               }
        }
 }
 ?>
index 32aa173ae859d29e282c93a1b0b51307371cf2c6..466c544b7f38398f058407a7734db75a2447658c 100644 (file)
@@ -1,4 +1,7 @@
 <?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++) {
index 6dcae5ad4367577c4b7e86c8bb26c93e806c2278..0a629ee47d8807daba4e8e97561a0593b0f83ffa 100644 (file)
@@ -255,8 +255,8 @@ class FeedAggregator
        public function addFeed($url)
        {
                $r = $this->setupRequest($url);
-        $r->send();
-        $this->handleResponse($r);
+               $r->send();
+               $this->handleResponse($r);
        }
 
        public function addFeeds($urls)
@@ -290,11 +290,11 @@ class FeedAggregator
 
        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)
@@ -312,8 +312,8 @@ class FeedAggregator
 
        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);
 
@@ -327,14 +327,14 @@ class FeedAggregator
        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);
+               }
        }
 }
 ?>