<commit_before># Development
This document describes how to setup a development environment on your 
system.

# Requirements
You need to have at least PHP 5.4 with built-in web server support. The 
latest version is recommended.

The following PHP modules need to be installed and activated:

* json
* spl
* pdo

## Fedora

    $ sudo dnf -y install php-cli php-pdo composer git

## Ubuntu

    $ sudo apt-get install php5-cli php5-curl php5-sqlite git

On Ubuntu you need to manually install [Composer](https://getcomposer.org). 

# Installation
Choose a working directory, clone the repository and run composer:

    $ git clone https://github.com/fkooman/php-remote-storage.git
    $ cd php-remote-storage
    $ composer install

Copy the configuration file:

    $ cp config/server.yaml.example config/server.yaml

Modify it to enable development mode and point to the correct locations for 
storage and the database. Here is a minimal configuration that should work:

    storageDir: /home/fkooman/Projects/php-remote-storage/data/storage
    serverMode: development
    Users:
        # foo:bar
        foo: $2y$10$sWzE0MjAP13srnNI/Pg8SuBM6LVmq8/hnznJwkQRF00Obe321PqGq
    Db:
        dsn: 'sqlite:/home/fkooman/Projects/php-remote-storage/data/rs.sqlite'

Create the directory and initialize the database:
    
    $ mkdir -p data/storage
    $ php bin/php-remote-storage-init

Now you can start the service from the CLI:

    $ php -S localhost:8080 -t web/ contrib/rs-router.php

You can now point your browser to http://localhost:8080/ and you should see
the welcome page.

## Development Mode
Development mode disables some features to make it work with the PHP 
web server:

* non-secure HTTP cookies are allowed;
* `X-SendFile` will not be used;

Make sure you do not enable this in production or test environments!

# Testing
You can run the included unit tests with PHPUnit:

    $ vendor/bin/phpunit

# API test suite
Some extra dependencies are needed to run the API test suite:

## Fedora

    $ sudo dnf -y install rubygem-bundler ruby-devel gcc-c++ redhat-rpm-config

## Ubuntu
It seems on Ubuntu 14.04 the included Ruby is too old to deal with multi byte
characters.

    $ sudo apt-get install ruby-dev bundler

Now install the test suite:

    $ git clone https://github.com/remotestorage/api-test-suite.git
    $ cd api-test-suite
    $ bundle install

You need to modify the configuration a bit to work with php-remote-storage:

    $ cp config.yml.example config.yml
<commit_msg>development mode instructions<commit_after># Development
This document describes how to setup a development environment on your 
system.

# Requirements
You need to have at least PHP 5.4 with built-in web server support. The 
latest version is recommended.

The following PHP modules need to be installed and activated:

* json
* spl
* pdo

## Fedora

    $ sudo dnf -y install php-cli php-pdo composer git

## Ubuntu

    $ sudo apt-get install php5-cli php5-curl php5-sqlite git

On Ubuntu you need to manually install [Composer](https://getcomposer.org). 

# Installation
Choose a working directory, clone the repository and run composer:

    $ git clone https://github.com/fkooman/php-remote-storage.git
    $ cd php-remote-storage
    $ composer install

Copy the configuration file:

    $ cp config/server.yaml.example config/server.yaml

Modify it to enable development mode and point to the correct locations for 
storage and the database. Here is a minimal configuration that should work:

    storageDir: /home/fkooman/Projects/php-remote-storage/data/storage
    serverMode: development
    Users:
        # foo:bar
        foo: $2y$10$sWzE0MjAP13srnNI/Pg8SuBM6LVmq8/hnznJwkQRF00Obe321PqGq
    Db:
        dsn: 'sqlite:/home/fkooman/Projects/php-remote-storage/data/rs.sqlite'

Create the directory and initialize the database:
    
    $ mkdir -p data/storage
    $ php bin/php-remote-storage-init

Now you can start the service from the CLI:

    $ php -S localhost:8080 -t web/ contrib/rs-router.php

You can now point your browser to http://localhost:8080/ and you should see
the welcome page.

## Development Mode
Development mode disables some features to make it work with the PHP 
web server:

* non-secure HTTP cookies are allowed;
* `X-SendFile` will not be used;

Development can be enabled in the configuration file `config/server.yaml`:
    
    ServerMode: development

Make sure you do not enable this in production or test environments!

# Testing
You can run the included unit tests with PHPUnit:

    $ vendor/bin/phpunit

# API test suite
Some extra dependencies are needed to run the API test suite:

## Fedora

    $ sudo dnf -y install rubygem-bundler ruby-devel gcc-c++ redhat-rpm-config

## Ubuntu
It seems on Ubuntu 14.04 the included Ruby is too old to deal with multi byte
characters.

    $ sudo apt-get install ruby-dev bundler

Now install the test suite:

    $ git clone https://github.com/remotestorage/api-test-suite.git
    $ cd api-test-suite
    $ bundle install

You need to modify the configuration a bit to work with php-remote-storage:

    $ cp config.yml.example config.yml

{'fraction_non_alphanumeric': 0.07049659201557935, 'fraction_numerical': 0.01207400194741967, 'mean_word_length': 3.4123711340206184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3044856', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1489, 'n_words': 605}