Very rough script to aid with migrating controllers presently from Slim 2.x to 3.x.
For 1.x move code to controllers first.
src
\Controllers
\Exporters
\Jobs
\Models
\Parsers
\Validators
#!/bin/bash | |
# | |
# Helper to upgrade Slim 1.x / 2.x projects to Slim 3.x | |
# | |
# Copyright (c) 2020 Jacques Marnweeck. All rights strictly reserved. | |
# | |
set -o errexit | |
export PS4='${BASH_SOURCE}:${LINENO}: ' | |
set -o xtrace | |
# | |
# $app = \Slim\Slim::getInstance(); | |
# | |
gsed -i'' -e '/Slim::getInstance();/d' *.php | |
# | |
# if ($app->request()->isPost()) { | |
# | |
gsed -i'' -e '/app->request()->isPost()/s/app->request()/request/g' *.php | |
# | |
# $post = $app->request()->post(); | |
# | |
gsed -i'' -e '/app->request()->post()/s/app->request()->post()/request->getParsedBody()/g' *.php | |
# | |
# $data = Pagination::paginate($app, 0, 200, 1, $query); | |
# | |
gsed -i'' -e '/Pagination::paginate/s/app/request/' *.php | |
# | |
# $app->notFound(); | |
# | |
gsed -i'' -e '/\$app->notFound();/s/\$app->notFound();/throw new NotFoundException(\$request, \$response);/g' *.php | |
gsed -i'' -e '/throw NotFoundException;/s/throw NotFoundException;/throw new NotFoundException;/g' *.php | |
gsed -i'' -e '/throw new NotFoundException;/s/throw new NotFoundException;/throw new NotFoundException(\$request, \$response);/g' *.php | |
# | |
# $app->redirect( | |
# | |
gsed -i'' -e '/\$app->redirect(/s/\$app->redirect(/return \$response->withRedirect(/g' *.php | |
# | |
# $app->urlFor( | |
# | |
gsed -i'' -e '/\$app->urlFor(/s/\$app->urlFor/\$this->container->get('\''router'\'')->pathFor/g' *.php | |
# | |
# $app->request_id | |
# | |
gsed -i'' -e '/\$app->request_id/s/\$app->request_id/$request->getAttribute('\''request_id'\'')/g' *.php | |
# | |
# $request_id | |
# | |
gsed -i'' -e '/\$request_id/s/\$request_id/$request->getAttribute('\''request_id'\'')/g' *.php | |
# | |
# return; | |
# | |
gsed -i'' -e '/return;/d' *.php | |
# | |
# Smarty | |
# | |
# | |
# Remove $app-> prefix infornt of templates | |
# | |
gsed -i'' -e '/app->template/s/app->//g' *.php | |
# | |
# Logger for monologger uses a container. | |
# | |
gsed -i'' -e '/app->log/s/app->log/logger/g' *.php | |
# | |
# Need to return \Slim\Http\Response with the rendered template | |
# | |
gsed -i'' -e '/\$template->display/s/);/));/g' *.php | |
gsed -i'' -e '/\$template->display/s/\$template->display/return \$response->write(\$template->fetch/g' *.php | |
# | |
# $id -> $args['id']; | |
# | |
gsed -i'' -e '/\$id/s/\$id/\$args['\''id'\'']/g' *.php | |
gsed -i'' -e '/\$bank_account_id/s/\$bank_account_id/\$args['\''bank_account_id'\'']/g' *.php |