<commit_before>laravel-repositories
====================

[![Build Status](https://travis-ci.org/reynholm-industries/laravel-repositories.svg)](https://travis-ci.org/reynholm-industries/laravel-repositories)

Repository pattern for Laravel

# Warning
This package is currently on development. Is not ready for use yet.
Interfaces may change.

# Installation and Configuration
to do: how to install with composer

# Usage
Simply extend one of the currently Reynholm\LaravelRepositories\Repository implementations
and provide connection and table name.

Currently available:
· Reynholm\LaravelRepositories\Repository\ArrayRepository
  Allows you to query and retrieve data only with arrays so there is no
  tight coupling with laravel or eloquent

## Example
```php
class UserArrayRepository extends ArrayRepository {
	//protected $connection = 'default';
    protected $tableName  = 'users';
}
```

Specify a connection string if is not the laravel's default connection.
Specify the database table.

Currently implemented methods:
```php
    /**
     * @param int $id
     * @param array $columns Restrict columns that you want to retrieve
     * @return array
     * @throws ColumnNotFoundException
     */
    public function find($id, array $columns = array());

    /**
     * @param int $id
     * @param array $columns Restrict columns that you want to retrieve
     * @return array
     * @throws ColumnNotFoundException
     * @throws EntityNotFoundException
     */
    public function findOrFail($id, array $columns = array());

    /**
     * @param array $criteria
     * Ex.:
     * array(
     *     array('name', '=', 'carlos'),
     *     array('age',  '>', 20),
     * )
     * @param array $columns Restrict columns that you want to retrieve
     * @return array
     * @throws ColumnNotFoundException
     * @throws InvalidCriteriaParametersException
     */
    public function findOne(array $criteria, array $columns = array());

    /**
     * @param int $id
     * @return boolean
     */
    public function delete($id);

    /**
     * @param int $id
     * @throw EntityNotFoundException
     */
    public function deleteOrFail($id);
```

## Validation
You can validate your data with the validate methods.
Specify the rules of your repository in the rules property:
```php
class UserArrayRepository extends ArrayRepository {

    protected $connection = 'default';
    protected $tableName  = 'users';
    protected $rules      = array(
        'name' => 'required|min:5|unique:users',
        'age'  => 'required|integer|between:0,120',
    );
}
```

Examples:
```php a boolean indicating if the data passed or not.
if ($this->arrayRepository->validate($validData)) {
    //The data is valid
}
else {<commit_msg>Added more info to readme.md<commit_after>laravel-repositories
====================

[![Build Status](https://travis-ci.org/reynholm-industries/laravel-repositories.svg)](https://travis-ci.org/reynholm-industries/laravel-repositories)

Repository pattern for Laravel

# Warning
This package is currently on development. Is not ready for use yet.
Interfaces may change.

# Installation and Configuration
to do: how to install with composer

# Usage
Simply extend one of the currently Reynholm\LaravelRepositories\Repository implementations
and provide connection and table name.

Currently available:
· Reynholm\LaravelRepositories\Repository\ArrayRepository
  Allows you to query and retrieve data only with arrays so there is no
  tight coupling with laravel or eloquent

## Example
```php
class UserArrayRepository extends ArrayRepository {
	//protected $connection = 'default';
    protected $tableName  = 'users';
}
```

Specify a connection string if is not the laravel's default connection.
Specify the database table.

Currently implemented methods:
```php
    /**
     * @param int $id
     * @param array $columns Restrict columns that you want to retrieve
     * @return array
     * @throws ColumnNotFoundException
     */
    public function find($id, array $columns = array());

    /**
     * @param int $id
     * @param array $columns Restrict columns that you want to retrieve
     * @return array
     * @throws ColumnNotFoundException
     * @throws EntityNotFoundException
     */
    public function findOrFail($id, array $columns = array());

    /**
     * @param array $criteria
     * Ex.:
     * array(
     *     array('name', '=', 'carlos'),
     *     array('age',  '>', 20),
     * )
     * @param array $columns Restrict columns that you want to retrieve
     * @return array
     * @throws ColumnNotFoundException
     * @throws InvalidCriteriaParametersException
     */
    public function findOne(array $criteria, array $columns = array());

    /**
     * @param int $id
     * @return boolean
     */
    public function delete($id);

    /**
     * @param int $id
     * @throw EntityNotFoundException
     */
    public function deleteOrFail($id);
    
    /**
     * Validates the input array and stores all the errors,
     * them, you can get them with the getErrors() method
     * @param array $data
     * @return boolean
     */
    public function validate(array $data);
    
    /**
     * Returns the errors generated by the validate methods
     * with the keys "messages" and "failed"
     * @return array
     */
    public function getValidationErrors();
```

## Validation
You can validate your data with the validate methods.
Specify the rules of your repository in the rules property:
```php
class UserArrayRepository extends ArrayRepository {

    protected $connection = 'default';
    protected $tableName  = 'users';
    protected $rules      = array(
        'name' => 'required|min:5|unique:users',
        'age'  => 'required|integer|between:0,120',
    );
}
```

Examples:
```php a boolean indicating if the data passed or not.
if ($this->arrayRepository->validate($validData)) {
    //The data is valid
}
else {
{'fraction_non_alphanumeric': 0.10868830290736985, 'fraction_numerical': 0.0023664638269100743, 'mean_word_length': 3.2752890173410405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3035170', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1566, 'n_words': 560}