Skip to content

Commit 3aacb5c

Browse files
authored
updates for slim v4 (GoogleCloudPlatform#1087)
1 parent f4111c2 commit 3aacb5c

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

appengine/php72/getting-started/composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"require": {
33
"google/cloud-storage": "^1.6",
4-
"slim/slim": "^3.0",
5-
"slim/twig-view": "^2.4"
4+
"slim/slim": "^4.0",
5+
"slim/twig-view": "^3.0",
6+
"slim/http": "^1.0",
7+
"slim/psr7": "^1.0"
68
},
79
"autoload": {
810
"psr-4": {

appengine/php72/getting-started/src/app.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@
2626

2727
// [END gae_php_app_storage_client_import]
2828

29-
$app = new Slim\App([
30-
'settings' => [
31-
'displayErrorDetails' => true,
32-
],
33-
]);
29+
$app = Slim\Factory\AppFactory::create();
30+
$app->addErrorMiddleware(true, true, true);
3431

3532
// Get container
3633
$container = $app->getContainer();

appengine/php72/getting-started/src/controllers.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
use Google\Cloud\Storage\Bucket;
2727

2828
$app->get('/', function (Request $request, Response $response) {
29-
return $response->withRedirect('/books');
29+
return $response
30+
->withHeader('Location', '/books')
31+
->withStatus(302);
3032
})->setName('home');
3133

3234
$app->get('/books', function (Request $request, Response $response) {
@@ -60,7 +62,9 @@
6062
}
6163
$id = $this->cloudsql->create($book);
6264

63-
return $response->withRedirect("/books/$id");
65+
return $response
66+
->withHeader('Location', "/books/$id")
67+
->withStatus(302);
6468
});
6569

6670
$app->get('/books/{id}', function (Request $request, Response $response, $args) {
@@ -109,7 +113,9 @@
109113
$book['image_url'] = $imageUrl;
110114
}
111115
if ($this->cloudsql->update($book)) {
112-
return $response->withRedirect("/books/$args[id]");
116+
return $response
117+
->withHeader('Location', "/books/$args[id]")
118+
->withStatus(302);
113119
}
114120

115121
return new Response('Could not update book');
@@ -128,7 +134,9 @@
128134
$object->delete();
129135
// [END gae_php_app_delete_image]
130136
}
131-
return $response->withRedirect('/books');
137+
return $response
138+
->withHeader('Location', '/books')
139+
->withStatus(302);
132140
}
133141

134142
return $response->withStatus(404);

appengine/php72/getting-started/test/CloudSqlTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function setUp() : void
3131
$dbUser = $this->requireEnv('CLOUDSQL_USER');
3232
$dbPass = $this->requireEnv('CLOUDSQL_PASSWORD');
3333
$dbName = getenv('CLOUDSQL_DATABASE_NAME') ?: 'bookshelf';
34-
$socket = "/cloudsql/${connection}";
34+
$socket = "/tmp/cloudsql/${connection}";
3535

3636
if (!file_exists($socket)) {
3737
$this->markTestSkipped(

appengine/php72/getting-started/test/ControllersTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919

2020
use Google\Cloud\TestUtils\TestTrait;
2121
use Google\Cloud\Samples\AppEngine\GettingStarted\CloudSqlDataModel;
22-
use Slim\Http\Environment;
23-
use Slim\Http\Request;
24-
use Slim\Http\Response;
22+
use Slim\Psr7\Factory\RequestFactory;
23+
use Slim\Psr7\Response;
2524
use PHPUnit\Framework\TestCase;
2625

2726
/**
@@ -48,8 +47,7 @@ public function setUp()
4847
public function testRoot()
4948
{
5049
$action = $this->getAction('home');
51-
$environment = Environment::mock();
52-
$request = Request::createFromEnvironment($environment);
50+
$request = (new RequestFactory)->createRequest('get', '/');
5351
$response = $action($request, new Response());
5452

5553
$this->assertEquals(302, $response->getStatusCode());
@@ -205,7 +203,9 @@ public function testRoot()
205203

206204
private function getAction($name)
207205
{
208-
$route = $this->app->getContainer()->get('router')->getNamedRoute($name);
206+
$route = $this->app->getRouteCollector()
207+
->getNamedRoute($name);
208+
209209
return $route->getCallable();
210210
}
211211
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"slim/slim": " ^3.0"
3+
"slim/slim": " ^4.0"
44
}
55
}

0 commit comments

Comments
 (0)