]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - extlib/HTTP/Request2/Observer/Log.php
Revert "Rebuilt HTTPClient class as an extension of PEAR HTTP_Request2 package, addin...
[quix0rs-gnu-social.git] / extlib / HTTP / Request2 / Observer / Log.php
diff --git a/extlib/HTTP/Request2/Observer/Log.php b/extlib/HTTP/Request2/Observer/Log.php
deleted file mode 100644 (file)
index b1a0552..0000000
+++ /dev/null
@@ -1,215 +0,0 @@
-<?php\r
-/**\r
- * An observer useful for debugging / testing.\r
- *\r
- * PHP version 5\r
- *\r
- * LICENSE:\r
- *\r
- * Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- *    * Redistributions of source code must retain the above copyright\r
- *      notice, this list of conditions and the following disclaimer.\r
- *    * Redistributions in binary form must reproduce the above copyright\r
- *      notice, this list of conditions and the following disclaimer in the\r
- *      documentation and/or other materials provided with the distribution.\r
- *    * The names of the authors may not be used to endorse or promote products\r
- *      derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package  HTTP_Request2\r
- * @author   David Jean Louis <izi@php.net>\r
- * @author   Alexey Borzov <avb@php.net>\r
- * @license  http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version  CVS: $Id: Log.php 272593 2009-01-02 16:27:14Z avb $\r
- * @link     http://pear.php.net/package/HTTP_Request2\r
- */\r
-\r
-/**\r
- * Exception class for HTTP_Request2 package\r
- */ \r
-require_once 'HTTP/Request2/Exception.php';\r
-\r
-/**\r
- * A debug observer useful for debugging / testing.\r
- *\r
- * This observer logs to a log target data corresponding to the various request \r
- * and response events, it logs by default to php://output but can be configured\r
- * to log to a file or via the PEAR Log package.\r
- *\r
- * A simple example:\r
- * <code>\r
- * require_once 'HTTP/Request2.php';\r
- * require_once 'HTTP/Request2/Observer/Log.php';\r
- *\r
- * $request  = new HTTP_Request2('http://www.example.com');\r
- * $observer = new HTTP_Request2_Observer_Log();\r
- * $request->attach($observer);\r
- * $request->send();\r
- * </code>\r
- *\r
- * A more complex example with PEAR Log:\r
- * <code>\r
- * require_once 'HTTP/Request2.php';\r
- * require_once 'HTTP/Request2/Observer/Log.php';\r
- * require_once 'Log.php';\r
- *\r
- * $request  = new HTTP_Request2('http://www.example.com');\r
- * // we want to log with PEAR log\r
- * $observer = new HTTP_Request2_Observer_Log(Log::factory('console'));\r
- *\r
- * // we only want to log received headers\r
- * $observer->events = array('receivedHeaders');\r
- *\r
- * $request->attach($observer);\r
- * $request->send();\r
- * </code>\r
- *\r
- * @category HTTP\r
- * @package  HTTP_Request2\r
- * @author   David Jean Louis <izi@php.net>\r
- * @author   Alexey Borzov <avb@php.net>\r
- * @license  http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version  Release: 0.4.1\r
- * @link     http://pear.php.net/package/HTTP_Request2\r
- */\r
-class HTTP_Request2_Observer_Log implements SplObserver\r
-{\r
-    // properties {{{\r
-\r
-    /**\r
-     * The log target, it can be a a resource or a PEAR Log instance.\r
-     *\r
-     * @var resource|Log $target\r
-     */\r
-    protected $target = null;\r
-\r
-    /**\r
-     * The events to log.\r
-     *\r
-     * @var array $events\r
-     */\r
-    public $events = array(\r
-        'connect',\r
-        'sentHeaders',\r
-        'sentBodyPart',\r
-        'receivedHeaders',\r
-        'receivedBody',\r
-        'disconnect',\r
-    );\r
-\r
-    // }}}\r
-    // __construct() {{{\r
-\r
-    /**\r
-     * Constructor.\r
-     *\r
-     * @param mixed $target Can be a file path (default: php://output), a resource,\r
-     *                      or an instance of the PEAR Log class.\r
-     * @param array $events Array of events to listen to (default: all events)\r
-     *\r
-     * @return void\r
-     */\r
-    public function __construct($target = 'php://output', array $events = array())\r
-    {\r
-        if (!empty($events)) {\r
-            $this->events = $events;\r
-        }\r
-        if (is_resource($target) || $target instanceof Log) {\r
-            $this->target = $target;\r
-        } elseif (false === ($this->target = @fopen($target, 'w'))) {\r
-            throw new HTTP_Request2_Exception("Unable to open '{$target}'");\r
-        }\r
-    }\r
-\r
-    // }}}\r
-    // update() {{{\r
-\r
-    /**\r
-     * Called when the request notify us of an event.\r
-     *\r
-     * @param HTTP_Request2 $subject The HTTP_Request2 instance\r
-     *\r
-     * @return void\r
-     */\r
-    public function update(SplSubject $subject)\r
-    {\r
-        $event = $subject->getLastEvent();\r
-        if (!in_array($event['name'], $this->events)) {\r
-            return;\r
-        }\r
-\r
-        switch ($event['name']) {\r
-        case 'connect':\r
-            $this->log('* Connected to ' . $event['data']);\r
-            break;\r
-        case 'sentHeaders':\r
-            $headers = explode("\r\n", $event['data']);\r
-            array_pop($headers);\r
-            foreach ($headers as $header) {\r
-                $this->log('> ' . $header);\r
-            }\r
-            break;\r
-        case 'sentBodyPart':\r
-            $this->log('> ' . $event['data']);\r
-            break;\r
-        case 'receivedHeaders':\r
-            $this->log(sprintf('< HTTP/%s %s %s',\r
-                $event['data']->getVersion(),\r
-                $event['data']->getStatus(),\r
-                $event['data']->getReasonPhrase()));\r
-            $headers = $event['data']->getHeader();\r
-            foreach ($headers as $key => $val) {\r
-                $this->log('< ' . $key . ': ' . $val);\r
-            }\r
-            $this->log('< ');\r
-            break;\r
-        case 'receivedBody':\r
-            $this->log($event['data']->getBody());\r
-            break;\r
-        case 'disconnect':\r
-            $this->log('* Disconnected');\r
-            break;\r
-        }\r
-    }\r
-    \r
-    // }}}\r
-    // log() {{{\r
-\r
-    /**\r
-     * Log the given message to the configured target.\r
-     *\r
-     * @param string $message Message to display\r
-     *\r
-     * @return void\r
-     */\r
-    protected function log($message)\r
-    {\r
-        if ($this->target instanceof Log) {\r
-            $this->target->debug($message);\r
-        } elseif (is_resource($this->target)) {\r
-            fwrite($this->target, $message . "\r\n");\r
-        }\r
-    }\r
-\r
-    // }}}\r
-}\r
-\r
-?>
\ No newline at end of file