{"id":18874177,"url":"https://github.com/joshuaestes/sfwebbrowserplugin","last_synced_at":"2026-02-17T00:30:19.125Z","repository":{"id":2496442,"uuid":"3470788","full_name":"JoshuaEstes/sfWebBrowserPlugin","owner":"JoshuaEstes","description":"git mirror","archived":false,"fork":false,"pushed_at":"2012-02-17T14:59:29.000Z","size":112,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-31T01:23:58.152Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.symfony-project.org/plugins/sfWebBrowserPlugin","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JoshuaEstes.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-17T14:57:51.000Z","updated_at":"2013-11-28T08:13:38.000Z","dependencies_parsed_at":"2022-09-09T07:50:19.285Z","dependency_job_id":null,"html_url":"https://github.com/JoshuaEstes/sfWebBrowserPlugin","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshuaEstes%2FsfWebBrowserPlugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshuaEstes%2FsfWebBrowserPlugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshuaEstes%2FsfWebBrowserPlugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshuaEstes%2FsfWebBrowserPlugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JoshuaEstes","download_url":"https://codeload.github.com/JoshuaEstes/sfWebBrowserPlugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239825062,"owners_count":19703210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T05:38:22.708Z","updated_at":"2026-02-17T00:30:19.040Z","avatar_url":"https://github.com/JoshuaEstes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"sfWebBrowser plugin\r\n===================\r\n\r\nThe `sfWebBrowserPlugin` proposes an HTTP client capable of making web requests. The interface is similar to that of `sfTestBrowser`.\r\n\r\nPossible uses\r\n-------------\r\n\r\n * Querying a Web service \r\n * Monitoring a Website\r\n * Mashup of content from several websites\r\n * Aggregation of RSS feeds\r\n * Proxy to another server\r\n * Cross-domain AJAX interactions\r\n * API to foreign websites\r\n * Fetch images and other types of content\r\n * ...\r\n\r\nContents\r\n--------\r\n\r\nThis plugin contains four classes: `sfWebBrowser`, `sfCurlAdapter`, `sfFopenAdapter`, and `sfSocketsAdapter`. Unit tests are available in the SVN repository, to be placed in a symfony application's `test/` directory.\r\n\r\nFeatures\r\n--------\r\n\r\nThe `sfWebBrowser` class makes web requests based on a URI:\r\n\r\n    [php]\r\n    $b = new sfWebBrowser();\r\n    $b-\u003eget('http://www.example.com/');\r\n    $res = $b-\u003egetResponseText();\r\n\r\nThe usual methods of the `sfTestBrowser` also work there, with the fluid interface.\r\n\r\n    [php]\r\n    // Inline\r\n    $b-\u003eget('http://www.example.com/')-\u003eget('http://www.google.com/')-\u003eback()-\u003ereload();\r\n    // More readable\r\n    $b-\u003eget('http://www.example.com/')\r\n      -\u003eget('http://www.google.com/')\r\n      -\u003eback()\r\n      -\u003ereload();\r\n\r\nThe browser accepts absolute and relative URIs\r\n\r\n    [php]\r\n    $b-\u003eget('http://www.example.com/test.html');\r\n    $b-\u003eget('test.html');\r\n\r\nThe `get()` method accepts parameters either as a query string, or as an associative array.\r\n\r\n    [php]\r\n    $b-\u003eget('http://www.example.com/test.php?foo=bar');\r\n    $b-\u003eget('http://www.example.com/test.php', array('foo' =\u003e 'bar'));\r\n\r\nPOST, PUT and DELETE requests are also supported.\r\n\r\n    [php]\r\n    $b-\u003epost('http://www.example.com/test.php', array('foo' =\u003e 'bar'));\r\n    $b-\u003eput('http://www.example.com/test.php', array('foo' =\u003e 'bar'));\r\n    $b-\u003edelete('http://www.example.com/test.php', array('foo' =\u003e 'bar'));\r\n\r\nYou can access the response in various formats, at your convenience:\r\n\r\n    [php]\r\n    $myString         = $b-\u003egetResponseText();\r\n    $myString         = $b-\u003egetResponseBody(); // drop the \u003chead\u003e part\r\n    $myDomDocument    = $b-\u003egetResponseDom();\r\n    $myDomCssSelector = $b-\u003egetResponseDomCssSelector();\r\n    $mySimpleXml      = $b-\u003egetResponseXml();\r\n\r\nYou can also interact with the response with the `setFields()` and `click()` methods.\r\n\r\n    [php]\r\n    $b-\u003eget('http://www.example.com/login')\r\n      -\u003esetField('user', 'foobar')\r\n      -\u003esetField('password', 'barbaz')\r\n      -\u003eclick('submit');\r\n\r\nThe browser supports HTTP and HTTPS requests, proxies, redirects, and timeouts.\r\n\r\nGzip and deflate content-encoded response bodies are also supported, provided that you have the [http://php.net/zlib zlib extention] enabled.\r\n\r\nAdapters\r\n--------\r\n\r\nThe browser can use various adapters to perform the requests, and uses the following selection order by default:\r\n\r\n * `sfCurlAdapter`: Uses [Curl](http://php.net/curl) to fetch pages. This adapter is a lot faster than `sfFopenAdapter`, however PHP must be compiled with the `with-curl` option, and the `curl` extension must be enabled in `php.ini` (which is rarely the case by default) for it to work. \r\n\r\n * `sfFopenAdapter`: Uses [`fopen()`](http://php.net/fopen ) to fetch pages. `fopen()` can take an URL as a parameter provided that PHP is compiled with sockets support, and `allow_url_fopen` is defined to `true` in `php.ini`. This is the case in most PHP distributions, so the default adapter should work in almost every platform. On the other hand, the compatibility has a cost: this adapter is slow.\r\n\r\n * `sfSocketsAdapter`: Uses [`fsockopen()`](http://php.net/fsockopen) to fetch pages.\r\n\r\nAlternatively, you can specify an adapter explicitly when you create a new browser object, as follows:\r\n\r\n    [php]\r\n    // use default adapter, i.e. sfCurlAdapter\r\n    $b = new sfWebBrowser(array());\r\n    // use sfFopenAdapter\r\n    $b = new sfWebBrowser(array(), 'sfFopenAdapter');\r\n\r\nCurrenly, `sfCurlAdapter` offers slightly more functionality than the other adapters. Namely, it supports multipart file uploads and cookies, which means you can login to a site as well as upload files via forms.\r\n\r\n    [php]\r\n    // upload files via a form\r\n    $b = new sfWebBrowser();\r\n    $b-\u003epost($url_of_form, array(\r\n      'file_field' =\u003e '/path/to/my/local/file.jpg'\r\n    ));\r\n    // login to a website\r\n    $b = new sfWebBrowser(array(), 'sfCurlAdapter', array('cookies' =\u003e true));\r\n    $b-\u003epost($url_of_login_form, array(\r\n      'user_field' =\u003e $username,\r\n      'pass_field' =\u003e $password\r\n    ));\r\n\r\nFull examples are available in the unit tests.\r\n\r\nError Handling\r\n--------------\r\n\r\n`sfWebBrowser` distinguishes to types of error: adapter errors and response errors. Thus, `sfWebBrowser` calls should be run this way :\r\n\r\n    [php]\r\n    $b = new sfWebBrowser();\r\n    try\r\n    {\r\n      if (!$b-\u003eget($url)-\u003eresponseIsError())\r\n      {\r\n        // Successful response (eg. 200, 201, etc)\r\n      }\r\n      else\r\n      {\r\n        // Error response (eg. 404, 500, etc)\r\n      }\r\n    }\r\n    catch (Exception $e)\r\n    {\r\n      // Adapter error (eg. Host not found)\r\n    }\r\n\r\nBesides, you should always remember that the response contents may contain incorrect code. Consider it as 'tainted', and therefore always use the [escaping](http://www.symfony-project.com/book/trunk/07-Inside-the-View-Layer#Output%20Escaping) when outputting it to a template.\r\n\r\n    [php]\r\n    // In the action\r\n    $this-\u003etitle = (string) $b-\u003egetResponseXml()-\u003ebody-\u003eh1\r\n\r\n    // In the template\r\n    \u003c?php echo $title // dangerous ?\u003e\r\n    \u003c?php echo $sf_data-\u003eget('title') // correct ?\u003e\r\n\r\nInstallation\r\n------------\r\n\r\n* Install the plugin\r\n\r\n        \u003e php symfony plugin:install sfWebBrowserPlugin  # for symfony 1.1 and 1.2\r\n        \u003e php symfony plugin-install http://plugins.symfony-project.com/sfWebBrowserPlugin    # for symfony 1.0\r\n\r\n* Clear the cache to enable the autoloading to find the new class\r\n\r\n        \u003e symfony cc\r\n\r\nKnown limitations\r\n-----------------\r\n\r\nCookies, caching, and file uploads are not yet supported in any of the packages (some of this functionality is available with `sfCurlAdapter`, see above).\r\n\r\nChangelog\r\n---------\r\n\r\n### Trunk\r\n\r\n### 2009-05-12 | 1.1.2 Stable\r\n\r\n  * francois: Fixed sfCurlAdapter destructor\r\n  * francois: Fixed sf1.2 compatibility issue for custom exception\r\n  * francois: Fixed a few limit case bugs and made the tests pass\r\n  \r\n### 2009-04-22 | 1.1.1 Stable\r\n\r\n  * francois: Fixed README syntax for parameters array\r\n  * bmeynell: Fixed custom options in `sfCurlAdapter`\r\n  \r\n### 2008-09-23 | 1.1.0 Stable\r\n\r\n  * francois: Translated README to Markdown\r\n  * francois: Added support for custom options in `sfCurlAdapter`\r\n  * francois: Added suppot for Timeout with `sfCurlAdapter` (based on a patch by adoanhuu)\r\n  * blacksun: Allow for SSL certificate verification\r\n  * francois: Added a test to check exceptions thrown by `getResponseXML`\r\n  * bmeynell: added multipart file upload support to `sfCurlAdapter`\r\n  * bmeynell: fixed regex in getResponseBody() which was returning an empty body\r\n  * bmeynell: `sfCurlAdapter`: Added new options: 'cookies', 'cookies_dir', 'cookies_file', 'verbose', 'verbose_log'\r\n  * bmeynell: `sfCurlAdapter`: Increased speed by Moving some initialization from call() to the constructer\r\n  * tristan:  Easier management of invalid XML responses\r\n  * francois: Fixed a bug in `sfFopenAdapter` error handler\r\n  * bmeynell: Added chunked transfer encoding support to `sfSocketsAdapter`\r\n  * bmeynell: Added support for 301 redirects in `sfSocketsAdapter`\r\n\r\n### 2007-03-27 | 1.0.1 stable\r\n\r\n  * bmeynell: Fixed a bug with `sfCurlAdapter` causing 'Bad Request' error responses\r\n  * francois: Fixed a bug with `get()` when `arg_separator.output` is not set to '\u0026' in `php.ini` (patch from river.bright)\r\n  * francois: Fixed a bug with `get()` when query string is already present in the url (based on a patch from Jeff Merlet)\r\n  * francois: Fixed auto-adapter decision in `sfWebBrowser::__construct()`\r\n  \r\n### 2007-03-08 | 1.0.0 stable\r\n\r\n  * francois: Added auto-adapter decision in `sfWebBrowser::__construct()`\r\n  * francois: Changed tested URLs a bit to avoid redirection issues with google\r\n  * bmeynell: Added `sfSocketsAdapter`\r\n  * bmeynell: `sfCurlAdapter`: more detailed error messages \u0026 leaner request setup\r\n\r\n### 2007-02-22 | 0.9.6 Beta\r\n\r\n * bmeynell, tristan: Allowed for requests with any method in `sfCurlAdapter`\r\n * tristan: Added `sfWebBrowser::responseIsError()`\r\n * tristan: Added `sfWebBrowser::getResponseMessage()`\r\n * tristan: Refactored error management in `sfFopenAdapter`\r\n\r\n### 2007-02-21 | 0.9.5 Beta\r\n\r\n * bmeynell: Fixed bug with relative uri's attempting to use a port other than 80 (sfWebBrowser, 132 - 146)\r\n * bmeynell: Fixed small bug not printing hostname on exception (sfFopenAdapter, 61-62)\r\n * bmeynell: Created sfCurlAdapter and passes all unit tests\r\n * bmeynell: Removed '$changeStack = true' from call() prototype in sfCurlAdapter, sfFopenAdapter, and moved changestack check to sfWebBrowser\r\n * bmeynell: Added $askeet_url to sfWebBrowserTest\r\n * bmeynell: Added easy toggling between adapters in sfWebBrowserTest\r\n * tristan: Added put() and delete() public methods\r\n * tristan: Added unit tests to validate request HTTP method\r\n\r\n### 2007-02-16 | 0.9.4 Beta\r\n\r\n * francois: Refactored the browser to make it multi-adapter\r\n * francois: '''BC break''' constructor signature changed : `new sfWebBrowser(array $headers, string $adapter_class, array $adapter_options)` \r\n * francois: Fixed notice when trying to retrieve inexistent header\r\n * francois: Fixed header case normalization\r\n * francois: Transformed setResponseXXX() methods to public\r\n * francois: Fixed caps in `initializeRequestHeaders()`\r\n * francois: Fixed unit test #40\r\n\r\n### 2007-02-16 | 0.9.3 Beta\r\n\r\n * tristan: Added support for gzip and deflate.\r\n * tristan: Possibility to pass default request headers to sfWebBrowser's constructor\r\n * tristan: \"Accept-Encoding\" header is automatically set depending on PHP capabilities\r\n * tristan: Fixed problems with request and response headers case \r\n * tristan: Renamed \"browser options\" to \"adapter options\" (http://www.symfony-project.com/forum/index.php/m/21635/)\r\n * tristan: '''BC break''' constructor signature changed : `new sfWebBrowser(array $headers, array $adapter_options)`\r\n * tristan: Unit tested POST requests  \r\n * tristan: Changed way httpd headers are stored internally\r\n * tristan: Fixed small bug in `getResponseBody()`\r\n * francois: Fixed unit test for malformed headers\r\n \r\n### 2007-02-09 | 0.9.2 Beta\r\n\r\n * francois: Fixed notice with `getResponseXML()`\r\n \r\n### 2007-02-08 | 0.9.1 Beta\r\n\r\n * francois: Fixed notice with some headers\r\n * francois: Added license and copyright\r\n \r\n### 2007-02-08 | 0.9.0 Beta\r\n\r\n * francois: Initial release\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshuaestes%2Fsfwebbrowserplugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshuaestes%2Fsfwebbrowserplugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshuaestes%2Fsfwebbrowserplugin/lists"}