There is no license information available for the latest version (4.0.6) of this package.

A set of tools in PHP

4.0.6 2016-09-23 21:10 UTC

README

Build Status Coverage Status

This is a standard library of tools that abstracts common work needed to be done across all projects.

Database Management

There are a couple of classes that make working with databases easier in projects. This is designed for use with Laravel, as they expose Eloquent models, however Laravel is not strictly necessary. The repository pattern allows for greater testability and easier to understand controllers. In your projects, simply create repositories that extend from ActiveRepositoryAbstract. For typehints you can use the contract ActiveRepository.

The active repository requires a Validator class to validate data processed within - this class is passed in via the constructor. You should either create your own validator implementing the Validator contract, or you can typehint the NullValidator to perform no validation on the model whatsoever.

class MyActiveRepository extends ActiveRepositoryAbstract 
{
    public function __construct(\Illuminate\Database\Eloquent\Model $model, \Depotwarehouse\Toolbox\Validation\NullValidator $validator)
    {
        $this->model = $model;
        $this->validator = $validator;
    }
}

Validators are simple to implement. They were designed with Laravel validators in mind. They exceptions they throw, ValidationExceptions, can be passed a failing Laravel Validator to construct an instance.

To implement a validator, simply make a class that implements the Validator interface. The two methods should do nothing if validation passes and throw a ValidationException if an error occurs.

Strings

Commonly projects have string related needs that aren't easily filled by the PHP standard library.

Strings\generateRandomString($length = 40) This generates a random (pseudorandom, do not use this for cryptographic or security purposes) string of the given length. The convenient usage for this is generate noninteger keys for a database table.

Strings\starts_with($haystack, $needle)

Strings\ends_with($haystack, $needle)

Laravel Integration

Errors Partial

This project ships with an Error Partial that displays errors, warnings and success messages at the top of the application page, based on a consistent format. To Install the Error Partial Handler in a Laravel application, add

Depotwarehouse\Toolbox\FrameworkIntegration\Laravel\ErrorPartialServiceProvider::class

to your config/app.php in the providers array. Next, you'll need to publish the view file with:

php artisan vendor:publish

Now in your layout page, where you want the errors to appear (likely at the top), simply add

@include('vendor.toolbox.errors.errorPartial')

Now errors, warnings and success messages will consistently render!

Testing

phpunit