multimedia-street / common
多媒体街道项目的常用功能
Requires
- php: >=5.5.9|~7.0
- barryvdh/laravel-cors: 0.8.*
- barryvdh/laravel-dompdf: 0.6.*
- doctrine/dbal: 2.*
- filp/whoops: 2.*
- illuminate/database: 5.*
- illuminate/support: 5.*
- intervention/image: 2.*
- intervention/imagecache: 2.*
- itsgoingd/clockwork: 1.*
- maatwebsite/excel: 2.*
- orangehill/iseed: 2.*
- predis/predis: 1.*
- symfony/http-kernel: 2.*
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2024-09-14 18:58:41 UTC
README
大多数多媒体街道项目的通用模板。
目录
包含的包
- Image - PHP 图像处理
- Image (Cache) - Intervention Image 类的缓存扩展
- iSeed - 逆向种子生成器
- Whoops - 酷 kids 的 PHP 错误处理
- Clockwork - PHP 开发的 Chrome 扩展
- DOMPDF - Laravel 5 的 DOMPDF 包装器
- Excel - Laravel Excel v2.1.* for Laravel 5
- CORS - Laravel 5 的 CORS
安装
通过 Composer
在您的 composer.json 中包含 multimedia-street/common
包并更新您的依赖项。
$ composer require multimedia-street/common
添加服务提供者
将服务提供者包含到您的 config/app.php
中的 providers 数组
Mmstreet\Common\ServiceProvider::class,
添加包外观
将外观包含到您的 config/app.php
中的 aliases 数组
'Excel' => Maatwebsite\Excel\Facades\Excel::class, 'PDF' => Barryvdh\DomPDF\Facade::class, 'Image' => Intervention\Image\Facades\Image::class,
禁用 API 的 CSRF 保护
如文档中所述,为了正确使用 CORS,在 App\Http\Middleware\VerifyCsrfToken
中,将您的路由添加到异常中
protected $except = [ 'api/*' ];
安装后
发布包配置
安装完成后,运行以下命令发布供应商
php artisan vendor:publish
扩展异常处理器
您可以使用特殊为开发而设计的异常处理器。这包括 Whoops。您可以使用 Mmstreet\Common\Exceptions\Handler
扩展您的 app/Exceptions/Handler.php
。另外,使用 $corsUris
属性添加您的 uris 以在 CORS 中使用。下面是一个示例。
namespace App\Exceptions; use Mmstreet\Common\Exceptions\Handler as ExceptionHandler; class Handler extends ExceptionHandler { protected $corsUris = [ 'api/*', // default 'auth/*', 'logout' ]; }
响应特性
您可以使用 Mmstreet\Common\Traits\ResponseTrait
到您的 App\Http\Controllers\Controller
以轻松返回 Json 或在 View 中返回响应。下面是一个示例。
namespace App\Http\Controllers; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Mmstreet\Common\Traits\ResponseTrait; abstract class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests, ResponseTrait; }
示例用法
namespace App\Http\Controllers; use App\Post; class PostController extends Controller { public function index() { $posts = Post::all(); if ($posts->isEmpty()) { // {The message}, {The data}, {status code}, {view name}, {response headers}, {Json callback} return $this->errorResponse('No Posts as of the moment', $posts, 404, 404, [], 'callback'); } return $this->successResponse('Successfully get all posts', $posts); } public function all() { $posts = Post::all(); if ($post->isEmpty()) { // You can also use Closure. return $this->errorResponse(function() { return response('No POSTS'); } } return $this->successResponse('Successfully get all posts', $posts); } }
变更日志
请参阅 CHANGELOG 以获取有关最近更改的更多信息。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CONDUCT 以获取详细信息。
安全
如果您发现任何安全问题,请通过 :author_email 发送电子邮件而不是使用问题跟踪器。
鸣谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 以获取更多信息。