Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
282 commits
Select commit Hold shift + click to select a range
36ef7b2
Added basic composer package outline.
Jan 10, 2013
732cdce
Added license.
Jan 10, 2013
8fc16db
Fixed whitespace issues.
Jan 10, 2013
ac1e3f7
Merge pull request #21 from Discovery-Software/master
Feb 13, 2013
b915110
Added check for Markdown submodule.
Feb 13, 2013
96acb8d
Fixed spelling error in error message.
Feb 13, 2013
9e3a52c
Cleaned up documentation and calling path.
Feb 18, 2013
f383d90
Cleaned up documentation.
Feb 18, 2013
df8a9fb
Split out encoders, as they are not often used.
Feb 18, 2013
c2d25fa
Documentation and whitespace cleanup.
Feb 18, 2013
1f7be96
Documentation cleanup.
Feb 18, 2013
c049d9f
Base PrestoPHP documentation and code cleanup. Root autoloaders moved…
Feb 18, 2013
5a901b0
Documentation and whitespace cleanup.
Feb 18, 2013
65f82a1
Whitespace and documentation cleanup.
Feb 18, 2013
e57834a
Documentation and whitespace cleanup.
Feb 18, 2013
7237301
Code and documentation cleanup.
Feb 18, 2013
d873433
Whitespace cleanup.
Feb 18, 2013
f9c6e4f
Merge pull request #30 from robotpony/1.1-cleanup
Feb 18, 2013
9228d53
Separated autoloaders.
Feb 18, 2013
c6a8fd9
Added internal APIs.
Feb 18, 2013
63c4bd6
Moved tests around.
Feb 18, 2013
cd8332e
Moved tests around.
Feb 18, 2013
8e24f58
Moved common functions to _helpers.
Feb 19, 2013
a84b76c
Extended helpers (adding commonly used idioms).
Feb 19, 2013
10a0b64
Cleaned up common usages, and added basics for containers.
Feb 19, 2013
6360d86
Improved trace logging (better format).
Feb 19, 2013
88f9e77
Routing extensions and cleanup:
Feb 19, 2013
5b84ade
Moved base delegate control to .htaccess (finishing work started in .9).
Feb 19, 2013
4e69101
Added trace logging for Presto and PHP errors.
Feb 19, 2013
6186927
Added basic dispatch tests.
Feb 19, 2013
c9fb443
Split out helpers.
Feb 19, 2013
75a0d5c
Migrated to simpler dispatch with multi-level support.
Feb 20, 2013
9bd6a4d
Fixed type usage after removing URI class.
Feb 20, 2013
d38cb53
Fixed dispatching (cleanup to call).
Feb 20, 2013
f703c97
API base cleanup. Removes:
Feb 21, 2013
ae72a0c
Added version check.
Feb 21, 2013
7a02839
Updated version number.
Feb 21, 2013
2713385
Added documentation.
Feb 22, 2013
c4e6d4d
Removed concept testing (autoloading also does this), and removed deb…
Feb 22, 2013
55a8ba3
Updated with new routes for innards.
Feb 22, 2013
426d01b
Updated to new version of Presto API.
Feb 22, 2013
1bd8d0b
Added tests.
robotpony Feb 22, 2013
84cefb1
Added APIs for infos.
robotpony Feb 22, 2013
62c5822
Added version test to built in routes.
robotpony Feb 22, 2013
6a447b0
Added changelog.
robotpony Feb 22, 2013
ca59a95
Added better lib versioning.
robotpony Feb 22, 2013
59dee3d
Added debugging tests + API.
robotpony Feb 22, 2013
ac3854c
Adding missing method description.
robotpony Feb 22, 2013
2610982
Added trace routing info.
robotpony Feb 23, 2013
762675a
Added a trace containing the _trace object (for error logging).
robotpony Feb 23, 2013
77389f6
Fixed info API parameter usage.
robotpony Feb 23, 2013
1b62488
Separated cmd output in tester for capturing commands for further tes…
robotpony Feb 23, 2013
0e2bcdd
Added docs to testing script.
robotpony Feb 25, 2013
7699f3b
Removed filtering logic (instead resources should rely on packages an…
Feb 25, 2013
c556cfd
Cleaned up documentation.
Feb 25, 2013
a35fef5
Added preflight calls for data scrubbing and model creation. Fixes #33.
Feb 25, 2013
8186d77
Added better documentation/output for command line tests.
Feb 25, 2013
9467e17
Removed tagged-sql extra class in favour of adhoc transforms
adam-patterson Feb 25, 2013
057ea8f
Added missing function docs
robotpony Mar 2, 2013
3ab8953
Cleaned up rewrite delegation check.
robotpony Mar 2, 2013
f885327
Relaxed rewrite delegation checks (to error logs now).
robotpony Mar 3, 2013
61039c5
Merge pull request #14 from robotpony/master
adam-patterson Mar 6, 2013
9234c1b
This undoes one change made to the robotpony/Presto source on master.…
adam-patterson Mar 6, 2013
42e06b6
Merge pull request #39 from Discovery-Software/robotpony-merge
adam-patterson Mar 6, 2013
f76b0ae
Request::content_type requires the extension passed in (from original…
adam-patterson Mar 11, 2013
3d923c6
Merge pull request #41 from robotpony/dsl-merge
Mar 12, 2013
334469e
Merge pull request #40 from robotpony/content-type-fix
Mar 12, 2013
d57d55d
Changed inesrt error to a 409 (is a client error, not a server error).
Mar 20, 2013
5bc8516
Removed update check.
Mar 20, 2013
ced5c65
Added redirect to response wrapper.
Mar 25, 2013
591399e
Added redirect to response class.
robotpony Apr 20, 2013
16b6cce
Merge branch '1.1-test-improvements' into 1.1-features
robotpony Apr 20, 2013
643917a
Issue #44. Include the html encoder file required to call the _encode…
adam-patterson Apr 30, 2013
ebd12aa
Fixes #44. Let the constructor return the object and set the render f…
adam-patterson Apr 30, 2013
89ae103
Extended view to have all-in-one helper.
May 29, 2013
dc82477
Merge branch 'view_extensions_all_in_one' into 1.1-features
May 29, 2013
b2df2a3
Adjusted base includes.
robotpony Jun 3, 2013
e3852b9
Improved view loader to use PHP path for finding views.
robotpony Jun 3, 2013
d2b62b2
Updated version.
Jun 4, 2013
5b253ee
Extended get/post access to allow for missing data.
robotpony Jun 12, 2013
988364e
Merge branch '1.1-features' of github.com:robotpony/Presto into 1.1-f…
robotpony Jun 12, 2013
4619eba
Resolving merge conflicts
ngallagher87 Jun 24, 2013
158a977
Merge pull request #38 from robotpony/1.1-features
ngallagher87 Jun 24, 2013
5cd8ad0
Added composer file.
Jun 24, 2013
4c782e5
Updated changelog with current release.
Jun 24, 2013
2145792
Updated README (for 1.1 merge).
Jun 24, 2013
e874306
Adds profiler tracing to presto output
adam-patterson Jun 24, 2013
5ffb3ae
Adds a class to make basic profiling easy.
adam-patterson Jun 24, 2013
0be625e
Issue #47. Updated to treat tracked profile data as structs.
adam-patterson Jun 24, 2013
083a54b
Issue #47. I have moved away from the toggle on/off approach and now …
adam-patterson Jun 25, 2013
38db8b9
Issue #47. Updated to only add profiler output to trace if some exist…
adam-patterson Jun 25, 2013
24f55b4
Merge pull request #48 from robotpony/profiler
adam-patterson Jun 26, 2013
583ef2b
Fixes #49. Support for array parameters in PDO wrapper. Adds two func…
adam-patterson Jul 3, 2013
2c9736d
Merge pull request #50 from robotpony/pdo-array-params
adam-patterson Jul 4, 2013
87afe5f
Updating path in the install docs
ngallagher87 Jul 9, 2013
cbce288
Removing a syntax error in the htaccess example
ngallagher87 Jul 9, 2013
b127c11
Merge pull request #52 from ngallagher87/master
Jul 9, 2013
91834d5
Re-merged commit 1b92b55fe351453bf0fa776a7e4554d41c69739e, relating t…
Jul 9, 2013
3675e86
Added missing QSA (so options are passed).
robotpony Jul 9, 2013
f5e50e6
Enabled JSONP for test requests.
robotpony Jul 9, 2013
58cacdd
Added basic JSONP support. Fixes #53.
robotpony Jul 9, 2013
df54356
Merge pull request #54 from robotpony/jsonp-response
adam-patterson Jul 10, 2013
841a542
Cleaned for service library exceptions.
robotpony Jul 19, 2013
d2bc25c
Hanldes binding an empty array properly. Converts the empty array to …
adam-patterson Jul 22, 2013
7cab3cb
Merge pull request #59 from robotpony/empty-array-param-fix
adam-patterson Jul 22, 2013
26db4b4
Query, update, insert, and delete parameters are now passed by value.
adam-patterson Jul 23, 2013
4e6d85a
Merge pull request #60 from robotpony/params-by-value
adam-patterson Jul 23, 2013
161bb93
Added scheme and tld to parsed URI elements. Allows generating URIs b…
Jul 23, 2013
ae4cbf3
Merge pull request #61 from robotpony/request-uri-extensions
Jul 23, 2013
c28ffd3
Added 303 to the possible status codes supported by Presto.
adam-patterson Jul 24, 2013
c91bb47
Adds support for multipart views to the View class.
adam-patterson Jul 24, 2013
2667cdc
Simplifies the processing by ensuring inout is an array (builds one i…
adam-patterson Jul 25, 2013
c65fcf9
Merge pull request #62 from robotpony/complex-views
adam-patterson Jul 25, 2013
574e699
Added 'select-objects' DB helper.
Jul 31, 2013
76ad4e5
Improved docs for db mapped types select helper.
Jul 31, 2013
632776f
Fixed quoting in examples.
Jul 31, 2013
4f6216b
Merge pull request #63 from robotpony/db-select-objects
Jul 31, 2013
a8a7276
Reset type if it isn't defined to prevent type cascading
ngallagher87 Jul 31, 2013
4cea8c3
Removing error log statments
ngallagher87 Jul 31, 2013
91aeec6
Merge pull request #64 from robotpony/type-reset
ngallagher87 Jul 31, 2013
3e9f99f
Coverted view 501 errors to 404 (to pass through to classes using vie…
Aug 1, 2013
e24f236
Whitespace cleanup.
Aug 6, 2013
232ddc4
Cleanup (mirrored from 1.2 branch).
Aug 8, 2013
c049fd3
Add a function that can be used to include an external file with nic…
adam-patterson Aug 8, 2013
89d0cc6
Merge pull request #67 from robotpony/view-extension
adam-patterson Aug 9, 2013
fc1378c
A first pass at a function to handle multiple insertions nicely.
adam-patterson Aug 12, 2013
d0b0ef6
Updates the mutli_insert function so that it expects keyed value pair…
adam-patterson Aug 12, 2013
e5d3312
Removed pronouns from error messages
adam-patterson Aug 12, 2013
0dda65b
Errors are now 500 codes
adam-patterson Aug 12, 2013
fbfff32
Merge pull request #69 from robotpony/multi-insert-fix
adam-patterson Aug 12, 2013
6cb2d36
Added per-row array object cast for easier PHP access.
robotpony Aug 12, 2013
7d052b0
Cleaned up trailing whitespace.
robotpony Aug 12, 2013
2c754ce
Merge pull request #70 from robotpony/objectize-row-arrays
ngallagher87 Aug 13, 2013
55ba108
Pulled 1.2 change for autoloader - ensures path is used for loading.
Aug 20, 2013
d4b8bd9
Merge branch 'master' of github.com:robotpony/Presto
Aug 20, 2013
4fa2aeb
Adds a function to allow individual API paths to support CORS request…
adam-patterson Aug 23, 2013
d314bbe
Merge pull request #73 from robotpony/cookies-for-cors-yum-yum
adam-patterson Aug 23, 2013
7b31a78
Testing this locally shows that the HTTP_ORIGIN header is expected to…
adam-patterson Aug 28, 2013
8121e4e
Turn assertion warnings on if the debug flag is set.
adam-patterson Aug 28, 2013
1a91184
Turning PRESTO_DEBUG on. It seems to me this should be on for develop…
adam-patterson Aug 28, 2013
91e2664
Fixed parameter spelling error. Added better 500 detail.
robotpony Sep 3, 2013
a6e90d5
Merge branch 'master' into service-exception-cleanup
robotpony Sep 3, 2013
06b1e25
Merge pull request #78 from robotpony/asserts-and-CORS-fix
adam-patterson Sep 3, 2013
31cc3c8
tee-hee
adam-patterson Sep 4, 2013
62343a7
Actual new function name for cross origin enabling function.
adam-patterson Sep 4, 2013
37dca4b
Merge pull request #82 from robotpony/CORS-function-name
adam-patterson Sep 4, 2013
85823e8
Added assertion settings and handling.
Sep 4, 2013
017af7f
Merge branch 'master' of github.com:robotpony/Presto
Sep 4, 2013
c0a8ddc
Fixed assertion hooks (missing param).
Sep 4, 2013
43a98a8
Relaxed service exceptions for 200/300 class responses. Improved retu…
Sep 5, 2013
e51e6c8
Added note for possible handling of 300 class responses in the servic…
Sep 5, 2013
218350f
Added body to trace parameters (allows debugging POSTs).
Sep 5, 2013
57f491c
Added body to JSON payload exception. Allows debugging of failed payl…
robotpony Sep 9, 2013
5715c04
Allows suppressing errors in php using
Sep 11, 2013
be67c90
Cleans up built in response type handlers, centralizing registration …
Sep 11, 2013
a126687
Fixes a comment typo.
Sep 11, 2013
a979484
Merge pull request #84 from robotpony/silent-error
Sep 11, 2013
82a8531
Merge branch 'master' of github.com:robotpony/Presto
Sep 11, 2013
cae9df3
Adds back testing tool symlinnks
Sep 11, 2013
e46faa9
Cleans up setup-tests routing (removing dead / invalid rules).
Sep 11, 2013
43c9088
Adds missing QSA to main doc delegation.
Sep 11, 2013
0de70a8
Adds a simple image GET test for issue #83.
Sep 11, 2013
31494d5
Switches service logging output to global trace functions, removing s…
Sep 11, 2013
889e3eb
Adds s2s test to basic setup tests.
Sep 11, 2013
0ffd1b2
Removes deprecated parameter.
Sep 11, 2013
43f596c
Adds missing test comments.
Sep 11, 2013
0d4564e
Fixes parameter trace (simplified).
Sep 11, 2013
2903c11
Simplifies S2S test.
Sep 11, 2013
80ecf82
Merge pull request #85 from robotpony/issue-83-content-rendering-in-d…
Sep 11, 2013
2bb4762
Adding a more detailed error for PDO bindings
ngallagher87 Sep 11, 2013
e7707a6
Merge pull request #86 from robotpony/pdo-binging-error
ngallagher87 Sep 12, 2013
212f6e2
Improves a trace message to include the name of the library making th…
Sep 19, 2013
d3305c2
Merge branch 'master' of github.com:robotpony/Presto
Sep 19, 2013
246762e
Adds referer (note mispelling) and helper `isInternalRequest()`. Prov…
robotpony Sep 23, 2013
ed4fdc3
Merge pull request #88 from robotpony/add-referer-and-helpers
robotpony Sep 23, 2013
55016d7
Fixes isInternalRequest to use host (versus URL)
robotpony Sep 23, 2013
f4d9df8
Fixes return of isInternal.
robotpony Sep 23, 2013
47ef9a8
Fix for requests without referrers.
robotpony Sep 23, 2013
486fe21
Removes limitation on redirect (no longer requires leading slash).
robotpony Sep 23, 2013
819afdc
Adjust redirect based on full versus partial request.
robotpony Sep 23, 2013
f047d45
Updates redirect to use self::hdr to populate header.
robotpony Sep 23, 2013
cfb4171
Cleans up whitespace.
robotpony Sep 23, 2013
c02c51f
Fixes location array.
robotpony Sep 23, 2013
68e050e
Added options to header output.
robotpony Sep 23, 2013
b9df61f
Including a db wrapper function that will format PDO params for you
ngallagher87 Sep 25, 2013
354c5c1
Causing unformatted parameters to be sent thru generate_params()
ngallagher87 Sep 25, 2013
d48f71c
Fixing syntax error
ngallagher87 Sep 25, 2013
30dba3b
Altering functions to support array values
ngallagher87 Sep 26, 2013
a56f92c
Adding context to functions
ngallagher87 Sep 26, 2013
3415faa
Formatting the is_bound() function to be more rigid
ngallagher87 Sep 26, 2013
079b929
Moving bind parameters logic into query()
ngallagher87 Sep 26, 2013
051aa1b
Moving valid pdo types into static class variable
ngallagher87 Sep 26, 2013
ba09830
Merge pull request #90 from robotpony/param-db-function
ngallagher87 Sep 26, 2013
93d7885
Pass the requet options along to objects so they are available for co…
adam-patterson Nov 12, 2013
e3c535f
Allow a cookie to be pased in on construction and use it for auth if …
adam-patterson Nov 12, 2013
cc78790
Make the attach function static so response and requests can be attac…
adam-patterson Nov 12, 2013
25a8e85
Attach the response and request to the API before construction making…
adam-patterson Nov 12, 2013
6f62f61
Merge pull request #93 from robotpony/session-mods
adam-patterson Nov 12, 2013
77571e9
Check if the c param is empty before attempting to access it. It will…
adam-patterson Dec 9, 2013
5c9a004
Also remove the c parameter as a required parameter. It is not requir…
adam-patterson Dec 9, 2013
dda32c9
Merge pull request #94 from robotpony/no-current-org
adam-patterson Jan 7, 2014
59686c5
Merging Bruce's CSV implementation to master
robotpony Dec 18, 2013
890aef4
Fixing merge conflicts
ngallagher87 Jan 13, 2014
b746946
Ensures filenames do not include `./`.
Jan 15, 2014
3c448f2
Fixes fatal log.
robotpony Jan 22, 2014
4aa1f85
Merge branch 'master' of github.com:robotpony/Presto
robotpony Jan 22, 2014
20a6a28
Sets errmode in our db instantiation code
adam-patterson Jan 27, 2014
52ed7ec
Merge pull request #98 from robotpony/db-fix
adam-patterson Jan 28, 2014
25ea60b
Allow existing singleton function to be called w/o credentials to ret…
adam-patterson Jan 30, 2014
cd43acb
Adds syslog logging for asserts.
robotpony Jan 31, 2014
5943a8a
Adjusts exception settings and output. Exceptions will now not bail t…
robotpony Jan 31, 2014
cc62a2a
Merge branch 'master' into db-time
adam-patterson Jan 31, 2014
d65aa75
Merge pull request #100 from robotpony/db-time
adam-patterson Jan 31, 2014
6cf7e07
Removes md lib.
robotpony Feb 3, 2014
f0789f1
Adds md library by file (instead of submodule).
robotpony Feb 3, 2014
17571b7
Merge branch 'master' of github.com:robotpony/Presto
robotpony Feb 3, 2014
da44129
Adds better logging for Service exceptions.
Feb 13, 2014
0e539f6
Improves error message when URL building fails.
Feb 13, 2014
1dbe43e
Adds GET query params.
robotpony Feb 14, 2014
318235f
Fixes URI parameter bug: invalid query option character.
robotpony Feb 17, 2014
44f7874
Adds basic query options for POST requests (and others).
robotpony Feb 17, 2014
a9c6868
Reverts body addition.
robotpony Feb 17, 2014
19d5a06
Reverts body param parsing changes. Adds basic URI encoding and body …
robotpony Feb 17, 2014
500669c
Improves Service trace, showing request and response bodies and param…
robotpony Feb 17, 2014
c0127d6
Have PUTs symmetrical to POSTs, not to OPTIONS
adam-patterson Feb 19, 2014
6d87334
Merge pull request #104 from robotpony/put-put-putty
adam-patterson Feb 19, 2014
a0f5aa3
Turns off verbose/debug mode by default.
Feb 20, 2014
8836d8a
Crank debugging up
adam-patterson Feb 21, 2014
e733833
Ensure the right CURLOPT gets set for put vs post
adam-patterson Feb 21, 2014
160d150
Ensure POSTFIELDS data is treated the same for POSTs and PUTs
adam-patterson Feb 21, 2014
ec39e30
Merge pull request #105 from robotpony/put-fix
adam-patterson Feb 24, 2014
c169d5a
Disables debug/trace by default.
Feb 25, 2014
9f42746
Adds base config file to ignore list.
Feb 25, 2014
da01111
Reverts a replace change, fixing request object.
Feb 25, 2014
5f12ef1
Adds row count as UPDATE return. Allows caller to check result (as > …
Feb 27, 2014
2c1033e
Adds a central model autoloader for simpler cases.
Apr 9, 2014
8867f75
Adds session updates, and cleans up auth token update cases (and docs)
Apr 16, 2014
25acdaa
Fixes a check that seemed to be incorrect.
robotpony Jun 24, 2014
df8cb06
Reverses check (assuming typo was the other way around).
robotpony Jun 24, 2014
ca28de0
convenience uri parsing object
adam-patterson Aug 1, 2014
d616326
Use URI object for referer and uri in request
adam-patterson Aug 1, 2014
eb845ce
Fixes typo
adam-patterson Aug 1, 2014
e50be18
Undoes previous approach for improved parsing. Adds path as a request…
adam-patterson Aug 7, 2014
417ad8f
Merge pull request #106 from robotpony/improved-uri-parsing
adam-patterson Aug 8, 2014
c08b4fb
Adds status code to service return errors. Improves consistency of er…
Aug 28, 2014
56e9f78
Cleans up service error messages.
Aug 28, 2014
e4a72ea
Fixes grammar error.
robotpony Oct 20, 2014
78c4007
Merge branch 'master' of github.com:robotpony/Presto
robotpony Oct 20, 2014
48c632e
Updates to log all exceptions. There is no reason to supress last cha…
robotpony Mar 3, 2015
56ebed0
Adds some spacing.
robotpony Mar 3, 2015
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Ignore generated log files.
/bin/*.log
/bin/token.test
/bin/token.test
_config.php
Empty file added .gitmodules
Empty file.
22 changes: 22 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

<IfModule mod_rewrite.c>

RewriteEngine On
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]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /docs/index.php?presto&page=$1 [NC,QSA,L]
</IfModule>


ErrorDocument 404 /docs/index.php?presto&error=404
ErrorDocument 500 /docs/index.php?presto&error=500
ErrorDocument 401 /docs/index.php?presto&error=401
ErrorDocument 403 /docs/index.php?presto&error=403
122 changes: 122 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Changelog

# 1.1 - *Sim Sala Bim*

**Presto 1.1 breaks compatibility with 1.0 in a few important areas:**

* Adds subfolder delegation
* Removes add_delegate*, URL, and other unused code (subfolder delegation is much simpler)
* Improves debugging (PHP errors to error log, added trace mode)
* Added unit tests
* Updated setup tests (to use internal API)
* `API` base startup has been simplified, removing the class pre-scanning mechanism. Presto will throw an exception if 1.0 usage is detected.
* API parameters are flattened to their obvious parts (get parameters, options, put/post body, resource type). This deprecates the `$ctx` object, which is still available via `self::$call`.
* `add_delegate` has been removed, as it has been replaced by folder delegation
* `add_filter` has been removed (a candidate 1.1 feature), as the other features provided enough utility on their own
* `Request::URI` has been removed in favour of a simpler builder function. URI parsing is now spread over `htaccess` for more obvious routing rules.

## Alpha 1 features

This patch adds a number of features planned for 1.1, including:

* Dispatching to folders of APIs
* Preflighting dispatch calls for parameter and model processing
* Adds internal testing and debugging APIs (only available when enabled)
* Adds command line unit testing tools
* Adds a trace mode, and better exception logging
* Adds routing information to exceptions (if trace is enabled)

## Updated parameter passing

The calling convention for delegate API functions has changed from:

public function get($ctx) { }
public function get_article($ctx) { }
public function put_article($ctx) { }

To the more verbose form:

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

This makes the call parameters clearer than they were in the past.

## Example folder delegation

Folder delegation uses Apache rewriting to map folders of APIs to specific URLs. For example, Presto uses it for internal delegation to its `transmogrify` APIs:

RewriteRule ^(transmogrify/(?:info|system|tests))/(.*)\.(.*)$ /lib/delegator-index.php?r=$2&t=$3&c=$1 [L]

This routes all requests to 3 specific folders within `transmogrify` to files within the folders `info/`, `system/`, and `tests/` in `transmogrify/`.

Requests like:

get "transmogrify/system/httpd/headers/content-type.json"

Are mapped to:

transmogrify/system/httpd.php::httpd->get_headers();

## Example preflight delegation

API calls can be split into two parts to simplify handling complex model creation and parameter processing. The split adds a preflight call to a *model* function of the same root name as the API itself.

Consider a simple GET:

get "transmogrify/system/httpd/headers/content-type.json"

This call can optionally be split into the model creation and the API call itself.

The model creation preflight call would be:

http.php::http->get_headers_model($p = array('content-type')) {
return new Features($p);
}

The call receives the standard API request parameters, returning a newly created model object of some sort. This call can be used to check parameters, check preconditions, and massage parameters into useful/predictable values for the API call itself:

http.php::http->get_headers($featureModel) {
}


## Example routing trace

If `PRESTO_TRACE` is enabled, exceptions will include:


[OPTIONS] transmogrify/info/delegation.json #0 [OK]
{
"_presto_trace": {
"request": "/transmogrify/info/delegation.json",
"routing_scheme": {
"action": "options",
"class": "delegation",
"container": "transmogrify/info",
"file": "transmogrify/info/delegation.php",
"method": "options",
"options": [],
"params": [],
"resource": "",
"type": "json"
},
"version": "presto-v1.10"
},
"code": 404,
"message": "Can't find delegation->options"
}


The `_presto_trace` element is added to make debugging easier. This trace is also available in the error log (in trace mode only):

[Fri Feb 22 16:38:58 2013] [error] [client 127.0.0.1] PRESTO: _presto_trace, {"routing_scheme":{"container":"transmogrify\\/info","class":"delegation","file":"transmogrify\\/info\\/delegation.php","resource":"","type":"json","action":"get","method":"get","params":[],"options":[]},"request":"\\/transmogrify\\/info\\/delegation.json","version":"presto-v1.10"}


# 1.0 - A la peanut butter sandwiches

* First public release
* Adds sub delegates and param filtering

# 0.8

* Adds basic URI -> class/member delegation and auto data return by type
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This file sets up Presto's delegator features, so that your classes are called i

4. Copy the example API file and test:

<pre>$ cp lib/presto/examples/info.php .
<pre>$ cp lib/presto/setup-tests/info.php .
$ curl [YOUR WEBROOT]/info.json
{"example":"This is some example information"}</pre>

Expand All @@ -41,4 +41,4 @@ The example API file writes a simple DOM (a `PHP` keyed array) as `JSON` back to

You need to enable the JSON extension using a custom RC (not a custom .ini). Find the instructions here:

* http://wiki.dreamhost.com/PHP.ini#Loading_PHP_5.3_extensions_on_all_domains_.28on_VPS_or_dedicated.29
* http://wiki.dreamhost.com/PHP.ini#Loading_PHP_5.3_extensions_on_all_domains_.28on_VPS_or_dedicated.29
19 changes: 0 additions & 19 deletions LICENSE

This file was deleted.

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

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

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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!**
121 changes: 58 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,86 +1,81 @@
Presto - PHP REST toolkit
=========================
# Presto 1.1

Presto is a small library for building simple, RESTful APIs using PHP. It's lightweight, decoupled, and focused on making web apps the right way; using APIs with clean URLs, which produce simple, clean output in standard formats like JSON, HTML, and XML.
*Frugal PHP + REST toolkit*

How is it 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.

Presto has no views, no models, and no controllers[^1]. Instead it focuses on APIs built from simple classes. It encourages applications to be based on APIs, which feed web applications animated with HTML/CSS/JavaScript.
## How is Presto different?

A Presto API is simply a PHP class that maps to a resource or tree of resources. It has:
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.

* Public members that map to requests (`GET thing/details.json` would map to `$thing->get_details()`)
* Request parameters and input payloads that are packaged up and sanitized
* Each route returns data as DOMs, which are automatically adapted to the requested `ContentType`
* Errors are automatically converted into returned HTTP statuses
### A quick example

The resulting code is focused on resources and the rules for those resources, and not boilerplate, excessive error checking, routing, and output generation.
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:

[^1]: Note that Presto avoids MVC by solving a smaller problem and relying on built in functionality for delegation and generating output.
GET fruit/apples/spartan.json?tags=large+red

How it works
------------

Presto uses the best parts of PHP and Apache, as they're intended to be used. It relies on `.htaccess` for routing, and built-in PHP behaviours for delegation and class loading. The principle is that relying on existing, simple approaches results in less framework, fewer bugs, and less to learn that isn't useful elsewhere.
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:

*Note: PHP 5.3 or better is requried, as Presto relies on anonymous functions, and other newer PHP features. This makes it possible to write very clean, simple web services.*

An example API
--------------

class info
extends API {

// Set up the API
public function __construct() {
parent::__construct(get_class());
if (!self::isSignedIn()) throw new Exception('Auth required', 401);
}

// GET info/time.json - gets the local machine time
public function get_time($ctx) {
$dom = (object) getdate();
return $dom; // <-- returns the DOM as JSON
/* Loaded from 'fruit/apples.php' */

class apples extends API {

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

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

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

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

return $thing; // to client in requested format
}

// PUT info/time.json
public function put_time($ctx) { throw new Exception('Not implemented', 501); }
// POST info/time.json
public function post_time($ctx) { throw new Exception('Not implemented', 501); }
}

The class promises a GET, PUT, and POST interface for time. All other requests will return a standard 404. The PUT and POST are not implemented yet, so they return a 501 (not implemented).

Presto maps requests to PHP files and objects, providing parameters and other calling information in the `$ctx` parameter. A request like:
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.

GET /info/time.json

Maps to:
Any HTTP request type is mapped automatically. For example, you can request a list of `apple` types available from the API:

[info.php] info->get_time($ctx);

The context includes the call parameters, the `content-type`, and request method. Handling of `content-type` is built in for simple cases, so that any data returned from an API is automatically transformed into the required type. For our simple example, returning the result of `datetime()` to the request produces:

{
"seconds" => 40
"minutes" => 58
"hours" => 21
"mday" => 17
"wday" => 2
"mon" => 6
"year" => 2003
"yday" => 167
"weekday" => "Tuesday"
"month" => "June"
"0" => 1055901520
}
LIST apples.json?colour=red

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

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

Advanced features
-----------------

There are a number of ways you can extend Presto. You can:
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:

public function list_seeds(/* … */) { array(); }

### What about errors?

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.

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

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

Presto translates the exception into a `400` with an appropriately encoded body.

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.


Other interesting features
==========================

You can also:

* 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

**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.**
14 changes: 0 additions & 14 deletions TODO.taskpaper

This file was deleted.

1 change: 0 additions & 1 deletion _tests/index.php

This file was deleted.

Loading