Closed akrabat closed 8 years ago
Lots of other things have been removed, too. Will add more as I think of them.
Removal of HTTP caching methods into separate components.
Relocation of \Slim\App::redirect into the Response class.
Change in middleware signature
//From
class AuthMiddleware extends \Slim\Middleware
{
public function call()
{ }
}
Too
$app->add(function ($request,$response,$next) {});
HTTP request and response changes to satisfy PSR-7
Removal of some components from core into separate components Flash Messages Cookies
urlFor()
is in Router
now
New \Slim\App
class name, and new \Slim\App constructor signature.
New minimum PHP version required.
Removal of crypto
How to read and parse request bodies based on content type
New Route Callback Signature
$app->get('/', function (\Psr\Http\Message\ServerRequestInterface $request,
\Psr\Http\Message\ResponseInterface $response, $args) {
//do stuff!
});
new url defintion for parameters
Edit: Good one! Note to self: be sure we link to FastRoute docs, too
Read and parse request bodies based on content type:
require 'vendor/autoload.php';
$app = new Slim\App();
//You want to make sure this one is as close to app->run
//Middlewares are run Last In First Executed
$app->add(function (\Psr\Http\Message\ServerRequestInterface $request,
\Psr\Http\Message\ResponseInterface $response $response, $next) {
switch($request->getHeader('Content-Type')) {
case 'your-content-type' : { //Keep in mind slim does define some basic parsers.
}
default : {
$response->withStatusCode(400)->withBody("Unsupported Content-Type");
}
}
return $response;
});
$app->run();
Hooks: Should be converted into Middleware.
Route Middleware is added differently.
Previously
$app->get('/', $mw, $mw2, function () {});
Now
$app->get('/', function () {})->add($mw2)->add($mw);
To get the container inside a route function, IE to replace the DI from slim 2.
$app->get('/', function () {
$container = $this->getContainer();
});
@akrabat @codeguy google doc for this? //cc @silentworks @lalop
No. It's part of https://github.com/slimphp/Slim-Documentation/tree/gh-pages
Optional Route Parameters need to be solidified
urlFor
=> pathFor
Also, pathFor
prepends a '/', so to create a fully qualified URL, you now need to do this:
$router = $this->router;
$uri = $request->getUri();
$url = $uri->getScheme() . '://' . $uri->getHost()
. $uri->getPort() ? ':' . $uri->getPort() : ''
. rtrim($uri->getBasePath(), '/')
. $router->pathFor('news-archive', ['year'=>'2015'], ['foo' => 'bar']);
SLIM MIGRATION GUIDE June 27th 2015 Glenn Eggleton geggleto@gmail.com
Slim Core has removed Stop/Halt. In your applications, you should transition to using the withStatusCode() and withBody()
Example In Slim 2.x:
$app->get(‘/’, function () { $app->halt(400, ‘Bad Request’); });
And now in Slim 3.x:
$app->get(‘/’, function ($req, $res, $args) { return $res->withStatus(400)->withBody(“Bad Request”); });
Slim v3 no longer has the concept of hooks. Hooks were removed as they duplicate the functionality already present in middlewares. You should be able to easily convert your Hook code into Middleware code.
Slim v3 no longer ships with HTTP Cache methods in core. It has been moved to its own separate repo (https://github.com/slimphp/Slim-HttpCache )
In Slim v2.x one would use the helper function $app->redirect(); to trigger a redirect request. In Slim v3.x one can do the same with using the Response class like so.
Example:
$app->get(‘/’, function ($req, $res, $args) {
return $res->withStatus(301)->withHeader(“Location”, “yournewuri”);
});
The middleware signature has changed from a class to a function
New signature: php $app->add(function ($req, $res, $next) {});
Application middleware is executed as Last In First Executed (LIFE)
In v3.0 the concept of flash messages has been removed. There currently is no planned feature for this, but could likely be a part of the Cookies package
In v3.0 cookies has been removed from core and moved to a separate component See (https://github.com/slimphp/Slim-Http-Cookies)
In v3.0 we have removed the dependency for crypto in core
Slim v3.0 requires php 5.4+
In v3.0 we have adopted a new callback signature
$app->get('/', function (\Psr\Http\Message\ServerRequestInterface $request,
\Psr\Http\Message\ResponseInterface $response, $args) {
//do stuff!
});
Slim now utilizes a new more powerful router ( https://github.com/nikic/FastRoute )!
The syntax for adding route middleware has changed slightly.
In v3.0:
php $app->get(…)->add($mw2)->add($mw1);
The wiki is not really being maintaned ...
Migration guide is in the v3 docs: http://www.slimframework.com/docs/start/upgrade.html
@geggleto there is helper method withRedirect for redirects :+1: Also php version: 5.5+
@dopesong Yeah I need to update the migrations docs this week.
1) Add Page to explain how the Container works with callables 2) Add Page to explain what the Immutability of the PSR-7 objects means
Added issues to Slim-Website.
We need a migrations guide.
This issue it to note what needs to go into it.