##API v2.0 Update I am pleased to announce that Stack.PHP has implemented some of the new changes introduced in version 2.0 of the API. You can now begin developing PHP applications that use v2.0 of the API.
These changes are still in beta and things are not expected to work perfectly yet. I have finished implementing all of the API methods. OAuth support has been completed and tested.
Definitely be sure to check out the new Stack.PHP website here:
http://stackphp.quickmediasolutions.comYour feedback is appreciated at this time - I'm sure there are many bugs to be uncovered and the sooner they are found, the better.
Don't know where to start?
Stack.PHP is a PHP library for accessing and retrieving information from the Stack Exchange APIBegin by checking out the Stack.PHP website.
Then Headhead over here for a quick tutorial on setting up and using Stack.PHP.
- A flexible caching system. Stack.PHP is designed to use as few API requests as possible. The library comes with two classes that can be set to automatically cache the responses of all API requests made: an SQL cache class (compatible with all database systems that have a PDO driver) and a filestore class (which stores the cached data on the filesystem). If none of the classes meets your needs, you can easily implement the
CacheBase
class in one of your own classes and customize it to your heart's content. - An intuitive pagination class. All requests (with perhaps one or two exceptions) return an instance of a
Response
orPagedResponse
object. This object provides an easy means of stepping through the objects returned. In the case of aPagedRequest
object, additional pages of data are automatically fetched as needed as you step through the data returned. This code that uses aResponse
andPagedResponse
object is basically identical. - Fully tested. The archives available for download and the code on Launchpad come with a
tests
folder. This folder contains an exhaustive test suite for Stack.PHP that runs through every API route, comparing the responses against expected output. These tests also make sure the utility code (such as the cache management code) is functioning as expected. - Fully documented. The entire codebase makes use of Doxygen comments throughout, making it easy to quickly generate HTML pages that describe in detail what each of the methods, enumerations, etc. do and any potential side effects you might encounter. The documentation can be found in the
doc
folder in the archives. - Easy to pick up and learn. To commemorate the first release in the 0.4 series, I have written a 7 page document on Google Docs which guides you through the basics of using the library.
- Complete support for authentication. Stack.PHP supports the API's OAuth 2.0 methods out-of-the-box and without any third-party libraries. Everything just works - and you can immediately get a feel for how authentication works by dropping an API key / ID into one of the examples and trying it out. Both the implicit and explicit authentication flows are supported.
- An organized exception class. Exceptions can come from all over the place in Stack.PHP (from cURL, from the cache classes, etc.), so it made sense to create a flexible exception class that captured the relevant information. You can see how this works by examining the test suite that is included with the library.
OutputHelper
class to save you from writing HTML / CSS / JS. When designing a web application that uses Stack.PHP, you will find yourself writing certain snippets of code again and again. Stack.PHP saves you from having to do this by offering a simpleOutputHelper
class that generates HTML / CSS / JS code for you. Do you want to generate a<select>
containing all Stack Exchange sites without their corresponding Metas? No problem - this can be solved with one line of code.- A full slate of real-world examples. It's one thing to know how to use Stack.PHP in theory. It's another thing to understand what typical and proper usage of the library looks like. That's why the library ships with a number of examples that demonstrate best practices and usage patterns - examples that range from really simple to very complex.
The latest beta release is 0.45 beta 1 and can be downloaded here:
http://launchpad.net/stackphp/0.5/0.5beta1/+download/stackphp-0.5beta1-source.tar.gz
The previous stable release can be found here:
http://launchpad.net/stackphp/0.4/0.4/+download/stackphp_source_0.4.zip
The previous stable version is available hereEven older versions:
http://launchpad.net/stackphp/0.3/stackphp0.3/+download/stackphp_0.3.tar.gz
Even older versions:
http://launchpad.net/stackphp/0.2/stackphp0.2/+download/stackphp_0.2.tar.gz
http://launchpad.net/stackphp/0.1/stackphp0.1/+download/stackphp_0.1.tar.gz
PHP 5.2 or higher is required for most of the library. The SQLite driver for the cache class has a bug that prevents it from working in PHP 5.2, however.