PHPackages                             rocker/server - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. rocker/server

ActiveLibrary[HTTP &amp; Networking](/categories/http)

rocker/server
=============

Boilerplate that helps you write RESTful web services on top of Slim framework (https://github.com/victorjonsson/PHP-Rocker#php-rocker)

1.3.0(12y ago)43489[1 issues](https://github.com/victorjonsson/PHP-Rocker/issues)2MITPHPPHP &gt;=5.3.2

Since May 2Pushed 11y ago7 watchersCompare

[ Source](https://github.com/victorjonsson/PHP-Rocker)[ Packagist](https://packagist.org/packages/rocker/server)[ Docs](https://github.com/victorjonsson/PHP-Rocker#php-rocker)[ RSS](/packages/rocker-server/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (10)Used By (2)

PHP-Rocker
==========

[](#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](https://github.com/codeguy/Slim) and an awesome [database facade](https://github.com/fridge-project/dbal). 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

[](#features)

- **User management**
- **CRUD operations** *Use the base classes in PHP-Rocker to extend the API with your own objects and operations*
- **EAV data model**
- **Static file storage** *With support for image manipulation and storage on [Amazon S3](https://github.com/victorjonsson/PHP-Rocker/wiki/File-storage-on-Amazon-S3)*
- **Built in object cache** *With support for APC and file based caching*
- **Interface based** *Easy to extend and to customize*
- **Administer remote servers from the console**
- **Automatically generated documentation** *Extracts all info from class files, meaning that you only have to write your documentation once*

#### Read more

[](#read-more)

- [System requirements](#system-requirements)
- [Installation](#installation)
- [API reference](#api-reference)
- [Extending the API with more operations](#extending-the-api-with-more-operations)
- [Adding your own objects](#adding-your-own-objects)
- [Manage remote servers via command line](#manage-remote-servers-via-command-line)
- [A note on security](#a-note-on-security)
- [Auto-generated documentation](#auto-generated-documentation)
- [Unit and acceptance testing](#unit-and-acceptance-testing)
- [License](#license)
- [Road map](#road-map)

#### Additional packages

[](#additional-packages)

- [Facebook login](https://github.com/victorjonsson/PHP-Rocker-facebook-login) Integrate your PHP-Rocker server with Facebook
- [Google login](https://github.com/victorjonsson/PHP-Rocker-google-login) Enable authenticated request with user credentials from Google

System requirements
-------------------

[](#system-requirements)

- **PHP v &gt;= 5.3.2**
- **MySQL** *The database layer has support several different databases (oracle, mssql, postgresql...) but PHP-Rocker is so far only tested with MySQL*
- **Web server (apache/nginx)** *If using nginx the .htaccess rewrite rules has to be moved to the rewrite configuration of the server*

Installation
------------

[](#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
-------------

[](#api-reference)

The API reference has moved to its own [wiki page](https://github.com/victorjonsson/PHP-Rocker/wiki/API-Reference).

Extending the API with more operations
--------------------------------------

[](#extending-the-api-with-more-operations)

Here you can [read more about how to create custom operations](https://github.com/victorjonsson/PHP-Rocker/wiki/Creating-a-custom-operation)

Adding your own objects
-----------------------

[](#adding-your-own-objects)

Here you can [read more about how to add your own objects](https://github.com/victorjonsson/PHP-Rocker/wiki/Creating-custom-objects)

Manage remote servers via command line
--------------------------------------

[](#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
------------------

[](#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

[](#other-authentication-packages)

- [Facebook login](https://github.com/victorjonsson/PHP-Rocker-facebook-login) Integrate your PHP-Rocker server with Facebook
- [Google login](https://github.com/victorjonsson/PHP-Rocker-google-login) Enable authenticated request with user credentials from Google

Auto-generated documentation
----------------------------

[](#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](https://raw.githubusercontent.com/wiki/victorjonsson/PHP-Rocker/php-rocker-doc.png?v=2)](https://raw.githubusercontent.com/wiki/victorjonsson/PHP-Rocker/php-rocker-doc.png?v=2)

```
