pquentin / sag Goto Github PK
View Code? Open in Web Editor NEWThis project forked from sbisbee/sag
A simple but powerful PHP library for talking to CouchDB.
Home Page: http://www.saggingcouch.com
License: Apache License 2.0
This project forked from sbisbee/sag
A simple but powerful PHP library for talking to CouchDB.
Home Page: http://www.saggingcouch.com
License: Apache License 2.0
Sag === Version 0.6.0 http://www.saggingcouch.com Sag is a PHP library for working with CouchDB. It is designed to not force any particular programming method on its users - you just pass PHP objects, and get stdClass objects and Exceptions back. This makes it trivial to incorporate Sag into your application, build different functionality on top of it, and expand Sag to incorporate new CouchDB functionality. Compatability ------------- Each Sag release is tested with an automated testing suite against CouchDB 1.0.x and 1.1.x, and PHP 5.3.x. Lower versions of CouchDB 0.11.x and 0.10.x, and PHP 5.2.x will likely work with Sag, but they are not officially supported, so your mileage may vary. If you are running pre-1.0.1 CouchDB or pre-5.3 PHP, then you probably want to look into updating your environment. Contents -------- CHANGELOG A detailed list of all changes between releases, including any breaking changes. LICENSE A copy of the license that Sag is released under. NOTICE Sag's copyright notice(s). README This file. Makefile Used to run unit tests, create releases, etc. examples/ Examples of how to use Sag. src/ This is the code that you will want to include in your application. src/Sag.php This is the core file that you will include() or require() in your code. src/SagException.php The SagException class. You don't need to include it. src/SagCouchException.php The SagCouchException class. You don't need to include it. src/SagCache.php The interface that all caching mechanisms extend. Include one of this interface's implementations instead of this file. src/SagFileCache.php Caching mechanism that uses the local file system. src/SagMemoryCache.php Caching mechanism that uses PHP objects in memory. Reported cache sizes are only semi-accurate, but are less important than file caching. src/SagConfigurationCheck.php A bootstrap file that Sag uses to make sure the environment will work with Sag. There is no reason you would need to call this directly, unless writing your own bootstrap scripts. src/SagUserUtils.php A set of utilities for interacting with CouchDB users and the _users database. tests/ The unit tests for Sag. You can ignore these files, though SagTests.php may be interesting for examples. Error Handling -------------- Sag's paradigm of simplicity is carried into its error handling by allowing you to send data to CouchDB that will result in errors (ex., malformed JSON). This is because CouchDB knows when there iss an error better than Sag. This also makes Sag more future proof, instead of worrying about each of CouchDB's API changes. Therefore, Sag will only look for PHP interface problems and issues that are native to PHP, such as passing an int instead of a stdClass. All errors are floated back to your application with Exceptions. Sag does not catch any errors itself, allowing your application to care about them or not. There are two types of exceptions: SagException For errors that happen within Sag, such as an invalid type being passed to a function or being unable to open a socket to the server. SagCouchException For errors generated by CouchDB (ex., if you pass it invalid JSON). The CouchDB error message will be put into the Exception's message ($e->getMessage()) and the HTTP status code will be the exception's code ($e->getCode()). You can catch these two types of exceptions explicitly, allowing you to split your error handling depending on where the error occurred, or implicitly by simply catching the Exception class. Networking ---------- Sag uses sockets, so there is no dependency on other libraries such as cURL. If you want to monitor your application's activity on the server side (ex., if you are proxying requests to CouchDB through a web server), then examine the HTTP User-Agent header. SSL is currently not supported. Results ------- When you have told Sag to decode CouchDB's responses (the default setting), they are stored in an object, breaking out the HTTP header lines and data. For example, running `print_r($sag->get('/1'));` (where '/1' is the location of a document) would give you something like this. `` stdClass Object ( [headers] => stdClass Object ( [_HTTP] => stdClass Object ( [raw] => HTTP/1.0 200 OK [version] => 1.0 [status] => 200 ) [Server] => CouchDB/0.10.0 (Erlang OTP/R13B) [Etag] => "1-4c6114c65e295552ab1019e2b046b10e" [Date] => Mon, 12 Apr 2010 23:01:39 GMT [Content-Type] => text/plain;charset=utf-8 [Content-Length] => 68 [Cache-Control] => must-revalidate ) [body] => stdClass Object ( [_id] => 1 [_rev] => 1-4c6114c65e295552ab1019e2b046b10e [foo] => bar ) ) '' HTTP protocol information is stored in $result->headers, its headers broken out as entries in the headers array - the "_HTTP" array element holds the basic HTTP information in raw form ($result->headers->_HTTP->raw), and then broken out into HTTP version number ($result->headers->_HTTP->version) and status code ($result->headers->_HTTP->status). The $result->body property holds the raw data from CouchDB, which you can have Sag automatically decode into PHP objects with json_decode(). If you've told Sag to not decode CouchDB's responses, then it'll only return the resulting JSON from CouchDB as a string (what would have been in the body property if you had set decode to true). None of the HTTP info is included. If CouchDB specifies Set-Cookies, then they will be stored in $result->cookies as a stdClass. Functions --------- Detailed documentation of the functions and API are available at http://www.saggingcouch.com/documentation.php. License ------- Sag is released under the Apache License, version 2.0. See the file named LICENSE for more information. Copyright information is in the NOTICE file. More? ----- See http://www.saggingcouch.com for more detailed information, bug reporting, planned features, etc.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.