krakphp / http Goto Github PK
View Code? Open in Web Editor NEWHttp Utilities for PSR-7 Frameworks
Http Utilities for PSR-7 Frameworks
return $rf(500, [], \vnu\api\error_struct('unhandled_exception', $ex->getMessage(), [
'exception' => [
'line' => $ex->getLine(),
'previous' => $ex->getPrevious(),
'file' => $ex->getFile(),
'trace' => explode("\n", $ex->getTraceAsString()),
]
]));
});
Create an HTTP request wrapper to add several convenience methods.
function aliasUriPath($app, $from, $to) {
return function($req, $next) use ($app, $from, $to) {
$from = Mw\Http\Util\joinUri($app['routes']->getPrefix(), $from);
$to = Mw\Http\Util\joinUri($app['routes']->getPrefix(), $to);
$path = $req->getUri()->getPath();
if ($path == $from || strpos($path, $from . '/') === 0) {
$to = str_replace($from, $to, $path);
$req = $req->withUri(
$req->getUri()->withPath($to)
);
}
return $next($req);
};
}
$admin['stacks.marshal_response']->push(function($res, $rf, $req, $next) {
if (!$res instanceof \Psr\Http\Message\StreamInterface) {
return $next($res, $rf, $req);
}
return $rf(200, [], $res);
});
We need an env package that sets $app['env'] and will use the DotEnv.
The redirect marshal response is incorrectly matching this: return [404, 'Feed Not Found']
Instead it should return a string body with 404 error status.
Build a simple class or function that builds full urls from mounted middleware. In a mounted middleware, the original request uri is backed up and replaced with the path relative to the mount. However, if one were to link urls, the urls would be wrong because they don't include the full path. The url builder takes a request and will prepend the proper path.
Move the Auto Args Package to use Krak AutoArgs
The mount middleware needs the ability to mount more than App instances.
With the release krakphp/mw we can now support pimple aware middleware
Remove the Mw\Http namespace and just the Http namespace to allow separation from the Mw package where it originated from. Don't worry about changing documentation and packagist names to account for change. It'll just be an vestige for now.
Wrap PSR-7 style middleware
function serveStatic($root) {
return function($req, $next) use ($root) {
$path = $req->getUri()->getPath();
$file_path = $root . $path;
if (!is_file($file_path)) {
return $next($req);
}
return $next->response(200, [
'Content-Type' => mime_content_type($file_path),
], fopen($file_path, "r"));
};
}
Add a new logging package that adds application and request logging via monolog.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.