Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
1422abb
Library folder cleanup and basic corrections. Making space for new fe…
robotpony Aug 2, 2013
72204fc
Added instal artifact folder.
robotpony Aug 2, 2013
504aefb
Cleaned up docs and added changelog link.
robotpony Aug 2, 2013
58a074e
Additional folder cleanup.
robotpony Aug 2, 2013
f149613
Removed profiler from inline portion of request. This should be added…
robotpony Aug 2, 2013
7d7486a
Additional cleanup, moving tests to better named files.
robotpony Aug 2, 2013
9e9218e
Cleaned up unused testing code.
robotpony Aug 2, 2013
a81a80a
Added missing ignore file.
robotpony Aug 2, 2013
92a67cf
Added start of makefile test script.
robotpony Aug 2, 2013
29dc3ea
Added start of makefile test script.
robotpony Aug 2, 2013
38b4dd1
Added basic GET tests.
robotpony Aug 2, 2013
4596aa5
Updated presto setup tests documentation.
robotpony Aug 2, 2013
d1e7693
Added test documentation.
robotpony Aug 2, 2013
8f0c24f
Added skeleton for additional tests.
robotpony Aug 2, 2013
66d1597
Added simple post tests.
robotpony Aug 2, 2013
b946e51
Cleaned up tests.
robotpony Aug 4, 2013
730dbe9
Additional cleanup and 1.2 goals.
robotpony Aug 4, 2013
335def1
Additional main README cleanup. Fewer words.
robotpony Aug 4, 2013
b89712d
Additional README cleanup. Better text.
robotpony Aug 4, 2013
a3bac68
Cleaned up README. More info for 1.2 version.
robotpony Aug 4, 2013
6cb211b
Updated navigation (adding beta/main).
robotpony Aug 4, 2013
5f075e0
Udpated styles: biggerfied everything. AM I GETTING OLD?
robotpony Aug 4, 2013
1e7460c
Updated credits.
robotpony Aug 4, 2013
a2d5181
Updated license.
robotpony Aug 4, 2013
ee4e3e5
Removed words.
robotpony Aug 5, 2013
911282d
Additional clarity.
robotpony Aug 5, 2013
171fc2e
Additional clarity.
robotpony Aug 5, 2013
42a9c22
Renamed unit tests.
robotpony Aug 5, 2013
d56f5bb
More README cleanup.
robotpony Aug 5, 2013
675f65a
Added DB example.
robotpony Aug 5, 2013
61f96bf
Cleaned up testing folder.
robotpony Aug 5, 2013
64025b7
Test cleanup: moved Makefile tests to old test harness. Added basic M…
robotpony Aug 5, 2013
115ec90
Fixed parameter ordering. Fixed parameter expansion (space bug).
robotpony Aug 5, 2013
9296d68
Cleaned up output of test tools.
robotpony Aug 5, 2013
85b2539
Fixed 201 test.
robotpony Aug 5, 2013
6bc7434
Additional test improvements (less encoding issue).
robotpony Aug 5, 2013
892376a
Added trace test handling
robotpony Aug 5, 2013
f40c4e6
Moved documentation to `docs/` folder.
robotpony Aug 7, 2013
918b213
Added style outline and DB docs.
robotpony Aug 7, 2013
bca9469
Fixed typo.
Aug 17, 2013
c638032
Set autoloaders to check path (instead of single file path).
Aug 17, 2013
5c5c074
Updated view basics.
Aug 17, 2013
8a01757
Fixed include paths and adjusted for new layout. Enabled trace/debugg…
robotpony Aug 18, 2013
73122d4
Added models as autoloader target and fixed introspection includes.
robotpony Aug 18, 2013
8b5cd6e
Cleaned up autoloader, including forcing include paths (versus specif…
robotpony Aug 18, 2013
58bb4f0
Added a simple HTML generation class, for generating fragments and mi…
robotpony Aug 18, 2013
d8c9206
Added custom assert handling, allowing assert() to produce clean Pres…
robotpony Aug 18, 2013
fd0b742
Fixed associative check.
robotpony Aug 18, 2013
59740cb
Added array nodes (to allow for UL, etc.).
robotpony Aug 20, 2013
e53c0b4
Reverted list version of API.
robotpony Aug 20, 2013
81ff6b1
Added outline for REST testing use of *service* lib.
Aug 22, 2013
9f34769
Cleaned up and namespaced bin files.
robotpony Aug 24, 2013
2e3a4af
Updated docs with namespace info.
robotpony Aug 24, 2013
ad1bc27
Moved Presto to a namespace. Updated autoloaders to consider namespaces.
robotpony Aug 24, 2013
7f5fab2
Merge pull request #76 from robotpony/namespace-ization
robotpony Aug 24, 2013
3e80eb2
Added phpunit and linter to package rules.
robotpony Aug 24, 2013
01aa0fb
Fixed coalesce/c for 0 case. Fixes #71.
robotpony Aug 24, 2013
9235355
Merged recent master changes.
robotpony Aug 24, 2013
9617807
Fixed commnent merge problem.
robotpony Aug 24, 2013
98fce05
Added bootstrap HTML class. Fixed bug in attrs() that resulted in non…
robotpony Aug 25, 2013
7ddaaf7
Added basic settings class (from chronicle) and unit tests.
robotpony Aug 25, 2013
e15cafc
Added key tests to settings class.
robotpony Aug 26, 2013
f3c4554
Added ignores for composer files.
robotpony Aug 26, 2013
1a4ee40
Hooked unit tests into makefiles
robotpony Aug 26, 2013
a6eae93
Updated service calling sequence (to allow for simple calls). Added b…
robotpony Aug 26, 2013
0afb1c0
Better service base test.
robotpony Aug 26, 2013
f210940
Merged 1.1 changes up.
robotpony Sep 3, 2013
9db2079
Adds a check to restrictTo to verify the context of the call is valid…
robotpony Sep 20, 2013
20018c3
Updates CTX style calling based on 1.1 changes.
robotpony Oct 3, 2013
3dc511a
Fixes copy-replace for 1.1->1.2 upgrade.
robotpony Oct 3, 2013
ba9483b
Updates various API uses to 1.2.
robotpony Oct 3, 2013
e90721f
Fixes multipart views.
Oct 16, 2013
f623724
Fixes db namespace bugs.
Oct 22, 2013
4aab858
Moves markdown to library.
Oct 23, 2013
3a3a605
Removes unused markdown library (moved to composer).
Oct 23, 2013
a3b3e60
Adds better error display.
Oct 29, 2013
c6e8c2b
Fixes error logging parameters.
Oct 30, 2013
8fa6209
Fixes exception reporting bug. Fixes whitespace.
Oct 30, 2013
50cccfe
Adds pretty printing in debug mode.
robotpony Nov 17, 2013
c56d0a6
Adds error check for missing class (if class file is found, but class…
robotpony Nov 30, 2013
25226e7
Adds a DOM base.
robotpony Nov 30, 2013
c439797
Adds shell blank methods and notes.
robotpony Nov 30, 2013
7c3c23a
Fixes error message. Adds defaults.
robotpony Dec 1, 2013
e226340
Adds a custom failure path for missing methods.
robotpony Dec 2, 2013
b7733fb
Merge branch '1.2-features' of github.com:robotpony/Presto into 1.2-f…
robotpony Dec 2, 2013
63fc698
Fixes assert use.
robotpony Dec 3, 2013
8fde9bf
Adds basic CSV.
robotpony Dec 18, 2013
8e8514f
Improves json pull.
robotpony Dec 18, 2013
d261150
Adds the error mode attribute setting code that was recently added in…
adam-patterson Jan 28, 2014
ee6714b
Merge pull request #99 from robotpony/db-tweak
adam-patterson Jan 28, 2014
80015f0
Making recent assert improvements available in 1.2
adam-patterson Jan 31, 2014
7d83391
Allow _instance to be called w/o credentials to get cached instance r…
adam-patterson Jan 31, 2014
d8ee60f
Merge pull request #102 from robotpony/assertion-fix
adam-patterson Jan 31, 2014
c196873
Merges 1.1 changes to 1.2 head. This may break things.
Feb 5, 2014
9b7e79e
Cleans up tests, in preparation for 1.2 release testing. Only one tes…
robotpony Feb 6, 2014
fa2a522
Allow PRESTO_BASE to be defined or overriden by client code.
robotpony Mar 22, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Ignore generated log files.
/bin/*.log
/bin/token.test
codekit-config.json
*.esproj
.DS_Store
composer\.lock
/vendor/
8 changes: 4 additions & 4 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(transmogrify/(?:info|system|tests))/(.*)\.(.*)$ /lib/delegator-index.php?r=$2&t=$3&c=$1 [L]
RewriteRule ^(transmogrify/(?:info|system|tests))/$ /lib/delegator-index.php?r=$1&t=LIST [L]
RewriteRule ^(transmogrify/.*)\.(.*)$ /lib/delegator-index.php?r=$1&t=$2 [L]
RewriteRule ^(transmogrify/.*)$ /lib/delegator-index.php?r=$1&t=LIST [L]
RewriteRule ^(introspector/(?:info|system|tests))/(.*)\.(.*)$ /lib/delegator-index.php?r=$2&t=$3&c=$1 [L]
RewriteRule ^(introspector/(?:info|system|tests))/$ /lib/delegator-index.php?r=$1&t=LIST [L]
RewriteRule ^(introspector/.*)\.(.*)$ /lib/delegator-index.php?r=$1&t=$2 [L]
RewriteRule ^(introspector/.*)$ /lib/delegator-index.php?r=$1&t=LIST [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /docs/index.php?presto&page=$1 [NC,QSA,L]
Expand Down
122 changes: 0 additions & 122 deletions CHANGELOG.md

This file was deleted.

4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Free, free, share-alike

Created by [Bruce Alderson](http://warpedvisions.org) (2011).
Created by [Bruce Alderson](http://warpedvisions.org) (2011 - 2013).

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Expand All @@ -9,4 +9,4 @@ The above copyright notice and this permission notice shall be included in all c

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

**PS: use, extend, share, enjoy. Thanks!**
**PS: use, extend, share, enjoy.**
120 changes: 88 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,137 @@
# Presto 1.1
<aside style="border: 1px solid rgba(0,0,0,.15); padding: 1em .5em; background-color: rgba(0,0,0,.05); text-align: center; font-size: 16pt; letter-spacing: 2px; margin-top: 2em;">
What's <a href="#1-2">planned for 1.2?</a> What's <a href="https://github.com/robotpony/Presto/pulls?direction=desc&page=1&sort=created&state=closed">changed so far in version 1.2</a>?
</aside>

*Frugal PHP + REST toolkit*
# Presto is different

Presto is a library for building RESTful APIs in PHP `5.3+`. It's lightweight, decoupled, and focused on making web apps the right way; using APIs and clean URLs to produce output in standard formats like JSON, HTML, and XML. It encourages separating views completely from your model and controller code, and to animate your user interfaces in HTML, CSS, and JavaScript. It also uses existing tools and libraries for what they're good at, like letting Apache deal with routing, and letting PHP load and execute a minimal amount of dynamic code.
PrestoPHP is a simple way to build RESTful web services APIs. It's a small toolkit that reduces how much code it takes to build a web service, letting you focus on what the service needs to do. It relies on the right tool for each part of a request; the web server for routing and PHP for loading, annotating, and for delegating a request to class member calls.

## How is Presto different?
Presto obsesses over APIs as a distinct, straightforward layer, and we think you should too.

Presto flattens standard MVC to fit REST requests better. It focuses on APIs built from simple classes, relying on the web server for routing and on PHP autoloading for delegating requests to class member calls. User interfaces are left to other toolkits, though Presto can serve up fragments of HTML with ease. Presto focuses on APIs.
## How simple is simple?

### A quick example
An API is built as a PHP class with members named for each resource (or tree of resources). For example, an `apple` is a resource. You can request an `apple` over HTTP.

An API is a class with members named for each resource (or tree of resources). For example, an `apple` is a resource. You can request an `apple` over HTTP:
GET fruit/apples/ripe.json?tags=large+red

GET fruit/apples/spartan.json?tags=large+red
Presto maps this request to a PHP file and class, as well as the specific class member. It loads the file, creates an instance of the class, and executes the member that relates to the request.

Presto loads 'fruit/apples.php'

Presto maps the request to a file, class, and class member automatically. It loads the file, creates an instance of the class, and executes the member that best fits:
The mapping is straightforward enough that navigating your code isn't a chore. Within the class file, it executes member functions based on the nature of the request, passing the parameters split by what they're for. It provides *parameters*, *options*, the *body* (if there is one), and the request *type*.

apples->get(
array('ripe'), /* parameters */
array('tags' => array('large', ''red)), /* options */
array() /* body */,
'json' /* requested content type */
);

How this mapping works can be configured simply in your Apache rewrite rules, though the built in mappings suffice for the majority of APIs you will encounter.

The `apples` class is based on the PrestoPHP `API` base.

/* Loaded from 'fruit/apples.php' */

class apples extends API {

public function get($params, $options, $body, $type) {

/* All error handling uses exceptions */

if (count($params) === 0)
throw new Exception('Missing required parameter', 400);
throw new \Exception('Missing required parameter', 400);

/* Exceptions are returned as valid HTTP/content type
responses */

$thing = (object) array(
/* Output is built up as PHP objects (like a DOM) */

$dom = (object) array(
'name' => $params[0],
'tags' => $options['tags']
);


return $thing; // to client in requested format
/* The $dom is converted to the content-type automatically */

return $dom;
}
}

There are a few exciting things in the example:

The `$thing` is automatically converted by Presto to the requested `Content-Type`, either implied by the request or the appropriate HTTP header. For formats not supported by default, *Output Adapters* can be defined and registered, or the type can be passed through for resources that are not based DOM style data.
1. The `$dom` is converted to the requested `Content-Type`, if it's a type that maps easily. This means that `JSON` and `XML` APIs require no special view code, as they can automatically be serialized.
2. HTTP status codes are returned automatically from any exception. This simplifies error handling and keeps it easy to read. PrestoPHP guarantees that all errors result in coherent service API responses.
3. HTTP request *verbs* are mapped to calls automatically. For example, you could request a `LIST` of `apple` types available, `DELETE` a specific `apple`, or provide a map of `OPTIONS`. This makes crafting expressive APIs possible.

Any HTTP request type is mapped automatically. For example, you can request a list of `apple` types available from the API:
Mapping verbs allows requests like:

LIST apples.json?colour=red

A LIST request is mapped to a function of the same name:
The request is mapped to a function of the same name:

public function list(/* … */) { return array(); }

More complex resources are possible using container requests a, multipart delegation, and custom rewrite rules. For example, you could add a `seeds` branch to the `apple` resource.

/* Built in multipart delegation */
public function list_seeds(/* … */) { return array(); }

More complex resources are possible by either delegating (based on regex patterns), or by adding specific handlers. For example, you could add a `seeds` branch to the `apple` resource. Getting a list of seeds would map to:
Additional segments of a URI automatically map to parameters.

public function list_seeds(/* … */) { array(); }
/* GET apples/seeds/14421.json */
public function get_seeds(array(14421), /*…*/) { return array(); }

### What about errors?
Containers are just folders of APIs, which are mapped by specific `HTACCESS` rules. By default, all APIs are either in the API root folder, or in a container folder. More specific rules can be added to your `HTACCESS ` routes to improve performance, or just to specifically limit the responses your service gives.

Errors are handled by the toolkit as standard PHP exceptions and standard PHP errors are remapped (where possible) to exceptions to ensure that logic and code errors are returned to clients as valid API returns. This means that individual APIs do not need to check return values, nor do they need to `try` and `catch` unless they need to do something special. Presto maps the standard exceptions to HTTP statuses and output in whatever format was requested where possible.

## Errors and statuses

Errors are standard PHP exceptions. Additionally, built-in PHP errors are mapped to exceptions (where possible) so that all logic and code errors are returned to clients as valid API returns. This means that individual APIs do not need to check return values, nor do they need to `try` and `catch` unless they need to do something special.

For example, if you encounter a parameter error you can simply throw an exception:

if (empty($param))
throw new Exception('Missing required parameter', 400);
throw new \Exception('Missing required parameter', 400);

Presto translates the exception into a `400` with an appropriately encoded body.
Presto translates the exception into an HTTP `400` status with an appropriately encoded body. This is especially interesting for built-in errors, as your code can ignore them entirely and allow PHP and Presto do their magic. Clients of your API will receive well-formed HTTP statuses and encoded bodies for every request.

The API code that results is much more focused on carefully testing parameters, retrieving appropriate resources, and building rich DOMs, rather than boilerplate code, managing responses, excessive error checking, routing, and other complex output generation.

## <a id="1-2"></a> Version 1.2 wishlist

The resulting API code is much more focused on carefully testing parameters, retrieving appropriate resources, and building rich DOMs instead of boilerplate code, managing responses, excessive error checking, routing, and other complex output generation.
*v1.2 toolkit feature candidates.*

1. **Install and command line helper.** Things like `presto install`, `presto add new-api-name`, and so on.
2. **Simple DB to object helper.** Allows simple object creation from `SELECT` syntax.
3. **File listing helper.** *From Chronicle.md*, returns objects from file and folder listings.
4. **Introspection.** Provides tools for asking Presto about itself, helpful for ops monitoring, setup, and troubleshooting.
5. **Testing tools.**
6. **Profiling tools.** *Added by @adam-patterson*
7. **Documentation tools**

Other interesting features
==========================
The focus of 1.2 is in making standard API code simpler for production. This includes all API tasks, not just code. Development, debugging, deployment, testing, profiling, and documentation. The completion of these and solid install / examples is the goal.

You can also:
### Database to object mappings

* Add additional `content-types` by adding *output adapters* (`JSON`, simple `XML`, and simple `HTML` are built in)
* Add `content-type` filters to define what types of payloads a given resource supports.
* Add *custom delegation* for special resource types
Simple things should be simple. Getting data from a table, for example, can produce simple PHP objects.

**Note that PHP 5.3 or better is required, as Presto relies on anonymous functions and other newer PHP features. This makes it possible to write very clean, simple web services.**
SELECT
UserID AS `id:int`,
FirstName AS `name.first`,
MiddleName AS `name.middle`,
LastName AS `name.last`
FROM SomeTable;

Using column aliases, Presto creates one set of objects per row, with the types hinted by in the `SELECT` aliases.

{
"people": [
{
"id": 1234,
"name": {
"first": "Bob",
"middle": "J",
"last": "Smith"
}
}
]
}
52 changes: 0 additions & 52 deletions _tests/simple-table.sql

This file was deleted.

9 changes: 0 additions & 9 deletions _tests/test-view.php

This file was deleted.

Loading