Home

Awesome

PHP-Rocker

Here you have yet another framework for writing RESTful web services in PHP, jay! What sets this framework apart from many of the others is that PHP-Rocker is a bundle of Slim and an awesome database facade. Not trying to write everything from scratch makes it possible for you to focus on what's important when writing your RESTful API and let other projects take care of things like routing and data storage.

Features

Read more

Additional packages

System requirements

Installation

1) Add file composer.json to your application directory with the following json configuration (notice that you must allow dev packages):

{
    "minimum-stability": "dev",
    "require" : {
        "rocker/server": "1.2.6"
    }
}

2) Run composer install in your application directory. This will install Slim and all other packages that PHP-Rocker is dependent on.

$ composer install

3) Run vendor/rocker/server/install.php in your application directory

$ php -f vendor/rocker/server/install.php

- You're done!

API reference

The API reference has moved to its own wiki page.

Extending the API with more operations

Here you can read more about how to create custom operations

Adding your own objects

Here you can read more about how to add your own objects

Manage remote servers via command line

First of move the console program to your bin directory so that you can access it from anywhere.

$ sudo ln -s /path/to/your/rocker/installation/console /bin/rocker

Having done that you add your server (you'll be prompted for server address and user credentials)

$ rocker server

Search for users

# Find users with nick containing John
$ rocker users -q 'nick=*John*'

# Find users coming from either France or Germany that is not admin
$ rocker users -q 'country=France|Germany&admin!=1'

# Find users that has a score greater than 80 and that has a description
# containing either "hockey" or "soccer"
$ rocker users -q 'score>=80&description=*hockey*|*soccer*'

Load user data

$ rocker users -l john.doe@website.com

You can also create, delete and update the users using the console program. Run rocker in the console to get more help.

A note on security

PHP-Rocker supports basic authentication and RC4 encrypted authentication out of the box. You should always run your web services on a SSL cert when handling business/user data, especially if you're using basic authentication. The RC4 encrypted authentication works basically the same as basic authentication except that the user credentials is encrypted on the client and decrypted on the server using a shared secret. If wanting to run RC4 encrypted requests you'll need to modify the parameter application.auth in config.php.

'application.auth' => array(
    'class' => '\\Rocker\\REST\\Authenticator',
    'mechanism' => 'RC4 realm="your.service.com"',
    'secret' => 'what-ever-hard-to-guess-string-you-want'
)

The secret also has to be given to the client communicating with your Rocker server. Pseudo code:

String crypted = RC4.encrypt("the-hard-to-guess-secret", "som.user@gmail.com:some-password");
request.addHeader("Authorization", "RC4 " + Base64.encode(crypted));

Other authentication packages

Auto-generated documentation

The documentation is automatically generated from the operation classes defined in config.php. The class documentation, URI of the operation and the allowed request methods will be added to the generated documentation. Take a look at index.php to see how the documentation is added to Slim's routing-system, you can also change to a template of your own.

Auto-generated documentation

<?php

/**
 * This text will extracted to the documentation, as well as @link declarations
 *
 * @link http://...
 */
class MyOperation extends \Rocker\REST\AbstractOperation {

Unit and acceptance testing

To run the unit tests of Rocker navigate to libs/Test and run phpunit. You can also run acceptance tests on your entire infrastructure using the dokimon tests

License

MIT license

Road map

Changelog

1.3.0 (unreleased)

1.2.6

1.2.0

1.1.8

1.1.7

1.1.6