depotwarehouse/toolbox 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

depotwarehouse/toolbox

Composer 安装命令:

composer require depotwarehouse/toolbox

包简介

A set of tools in PHP

README 文档

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

统计信息

  • 总下载量: 12.47k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-07-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固