All Projects → middlewares → utils

middlewares / utils

Licence: MIT license
Common utils used by PSR-15 middlewares

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to utils

Stdlib
✨ Standard library for JavaScript and Node.js. ✨
Stars: ✭ 2,749 (+5748.94%)
Mutual labels:  utils
BaseToolsLibrary
Android通用适配器和常用的工具类
Stars: ✭ 24 (-48.94%)
Mutual labels:  utils
GoGPUtils
Enhance productivity and avoid to reinvent the wheel every time that you start a Go project
Stars: ✭ 29 (-38.3%)
Mutual labels:  utils
Flutter commonapp
打造一款通用的AppUI结构,包括登录、注册等通用 UI 界面及各工具类和公共部分。
Stars: ✭ 227 (+382.98%)
Mutual labels:  utils
dt-utils
前端常用工具函数
Stars: ✭ 23 (-51.06%)
Mutual labels:  utils
PowerUp
⚡ Decompilation Tools and High Productivity Utilities ⚡
Stars: ✭ 1,526 (+3146.81%)
Mutual labels:  utils
Jsonapi Utils
Build JSON API-compliant APIs on Rails with no (or less) learning curve.
Stars: ✭ 191 (+306.38%)
Mutual labels:  utils
mUtils
JavaScript常用方法
Stars: ✭ 59 (+25.53%)
Mutual labels:  utils
lancet
A comprehensive, efficient, and reusable util function library of go.
Stars: ✭ 2,228 (+4640.43%)
Mutual labels:  utils
relay-helpers
Helpers to simplify and enhance Relay (https://facebook.github.io/relay/)
Stars: ✭ 19 (-59.57%)
Mutual labels:  utils
Prosemirror Utils
⚒ Utils library for ProseMirror
Stars: ✭ 241 (+412.77%)
Mutual labels:  utils
Pandora
潘多拉的魔盒了解一下。
Stars: ✭ 248 (+427.66%)
Mutual labels:  utils
fileutils
Golang file system utils such as copy files and directories
Stars: ✭ 19 (-59.57%)
Mutual labels:  utils
Bbo
bbo is a utility library of zero dependencies for javascript. 🍖🌭🍔
Stars: ✭ 227 (+382.98%)
Mutual labels:  utils
ramdu
Small utils set built around Ramda
Stars: ✭ 18 (-61.7%)
Mutual labels:  utils
Goutil
💪 Helper Utils For The Go: string, array/slice, map, format, cli, env, filesystem, test and more. Go 的一些工具函数,格式化,特殊处理,常用信息获取等等
Stars: ✭ 205 (+336.17%)
Mutual labels:  utils
fat ecto
Query mechanism for Ecto
Stars: ✭ 20 (-57.45%)
Mutual labels:  utils
Comet
iOS 项目的 Swift 基础库,提供常用组件、便利方法等。支持 Swift 3.x、Swift 4.x,iOS 8.0+
Stars: ✭ 49 (+4.26%)
Mutual labels:  utils
wx-tool
微信小程序工具类
Stars: ✭ 31 (-34.04%)
Mutual labels:  utils
XinFramework
Android 快速开发框架 总结以往开发结合三方项目 不断更新
Stars: ✭ 21 (-55.32%)
Mutual labels:  utils

middlewares/utils

Latest Version on Packagist Software License Testing Total Downloads

Common utilities used by the middlewares' packages:

Installation

This package is installable and autoloadable via Composer as middlewares/utils.

composer require middlewares/utils

Factory

Used to create PSR-7 and PSR-17 instances. Detects automatically Diactoros, Guzzle, Slim, Nyholm/psr7 and Sunrise but you can register a different factory using the psr/http-factory interface.

use Middlewares\Utils\Factory;
use Middlewares\Utils\FactoryDiscovery;

// Create PSR-7 instances
$request = Factory::createRequest('GET', '/');
$serverRequest = Factory::createServerRequest('GET', '/');
$response = Factory::createResponse(200);
$stream = Factory::createStream('Hello world');
$uri = Factory::createUri('http://example.com');
$uploadedFile = Factory::createUploadedFile($stream);

// Get PSR-17 instances (factories)
$requestFactory = Factory::getRequestFactory();
$serverRequestFactory = Factory::getServerRequestFactory();
$responseFactory = Factory::getResponseFactory();
$streamFactory = Factory::getStreamFactory();
$uriFactory = Factory::getUriFactory();
$uploadedFileFactory = Factory::getUploadedFileFactory();

// By default, use the FactoryDiscovery class that detects diactoros, guzzle, slim, nyholm and sunrise (in this order of priority),
// but you can change it and add other libraries

Factory::setFactory(new FactoryDiscovery(
    'MyApp\Psr17Factory',
    FactoryDiscovery::SLIM,
    FactoryDiscovery::GUZZLE,
    FactoryDiscovery::DIACTOROS
));

//And also register directly an initialized factory
Factory::getFactory()->setResponseFactory(new FooResponseFactory());

$fooResponse = Factory::createResponse();

Dispatcher

Minimalist PSR-15 compatible dispatcher. Used for testing purposes.

use Middlewares\Utils\Dispatcher;

$response = Dispatcher::run([
    new Middleware1(),
    new Middleware2(),
    new Middleware3(),
    function ($request, $next) {
        $response = $next->handle($request);
        return $response->withHeader('X-Foo', 'Bar');
    }
]);

CallableHandler

To resolve and execute a callable. It can be used as a middleware, server request handler or a callable:

use Middlewares\Utils\CallableHandler;

$callable = new CallableHandler(function () {
    return 'Hello world';
});

$response = $callable();

echo $response->getBody(); //Hello world

HttpErrorException

General purpose exception used to represent HTTP errors.

use Middlewares\Utils\HttpErrorException;

try {
    $context = ['problem' => 'Something bad happened'];
    throw HttpErrorException::create(500, $context);
} catch (HttpErrorException $exception) {
    $context = $exception->getContext();
}

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].