Skip to content

Commit c41448f

Browse files
committed
Merge branch 'master' into add-subdir-var
2 parents b20b338 + 317ec92 commit c41448f

File tree

115 files changed

+847
-823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+847
-823
lines changed

appengine/flexible/analytics/app.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,26 @@
1616
*/
1717

1818
use GuzzleHttp\Client;
19-
use Silex\Application;
20-
use Silex\Provider\TwigServiceProvider;
21-
use Symfony\Component\HttpFoundation\Request;
19+
use Psr\Http\Message\ServerRequestInterface as Request;
20+
use Psr\Http\Message\ResponseInterface as Response;
21+
use Slim\Factory\AppFactory;
22+
use Slim\Views\Twig;
23+
use Slim\Views\TwigMiddleware;
2224

23-
// create the Silex application
24-
$app = new Application();
25-
$app->register(new TwigServiceProvider());
26-
$app['twig.path'] = [ __DIR__ ];
25+
// Create App
26+
$app = AppFactory::create();
2727

28-
$app->get('/', function (Application $app, Request $request) {
29-
/** @var Twig_Environment $twig */
30-
$twig = $app['twig'];
31-
$trackingId = $app['GA_TRACKING_ID'];
28+
// Display errors
29+
$app->addErrorMiddleware(true, true, true);
30+
31+
// Create Twig
32+
$twig = Twig::create(__DIR__);
33+
34+
// Add Twig-View Middleware
35+
$app->add(TwigMiddleware::create($app, $twig));
36+
37+
$app->get('/', function (Request $request, Response $response) use ($twig) {
38+
$trackingId = getenv('GA_TRACKING_ID');
3239
# [START gae_flex_analytics_track_event]
3340
$baseUri = 'http://www.google-analytics.com/';
3441
$client = new GuzzleHttp\Client(['base_uri' => $baseUri]);
@@ -44,12 +51,13 @@
4451
'el' => 'Hearts', # Event label.
4552
'ev' => 0, # Event value, must be an integer
4653
];
47-
$response = $client->request('POST', 'collect', ['form_params' => $formData]);
54+
$gaResponse = $client->request('POST', 'collect', ['form_params' => $formData]);
4855
# [END gae_flex_analytics_track_event]
49-
return $twig->render('index.html.twig', [
50-
'base_uri' => $baseUri,
51-
'response_code' => $response->getStatusCode(),
52-
'response_reason' => $response->getReasonPhrase()]);
56+
return $twig->render($response, 'index.html.twig', [
57+
'base_uri' => $baseUri,
58+
'response_code' => $gaResponse->getStatusCode(),
59+
'response_reason' => $gaResponse->getReasonPhrase()
60+
]);
5361
});
5462

5563
return $app;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"require": {
3-
"silex/silex": "^2.3",
4-
"twig/twig": "^1.24",
5-
"guzzlehttp/guzzle": "^7.0",
6-
"symfony/css-selector": "^3.1"
3+
"slim/slim": "^4.0",
4+
"slim/psr7": "^1.3",
5+
"slim/twig-view": "^3.2",
6+
"guzzlehttp/guzzle": "^7.0"
77
}
88
}

appengine/flexible/analytics/index.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@
2323

2424
// Run the app!
2525
// use "gcloud app deploy"
26-
$app['debug'] = true;
27-
$app['GA_TRACKING_ID'] = getenv('GA_TRACKING_ID');
2826
$app->run();

appengine/flexible/analytics/test/LocalTest.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,25 @@
1616
*/
1717
namespace Google\Cloud\Samples\AppEngine\Analytics;
1818

19-
use Silex\WebTestCase;
19+
use PHPUnit\Framework\TestCase;
20+
use Google\Cloud\TestUtils\TestTrait;
21+
use Slim\Psr7\Factory\RequestFactory;
2022

21-
class LocalTest extends WebTestCase
23+
class LocalTest extends TestCase
2224
{
23-
public function setUp(): void
24-
{
25-
parent::setUp();
26-
$this->client = $this->createClient();
27-
}
25+
use TestTrait;
2826

29-
public function createApplication()
27+
public function testIndex()
3028
{
29+
$this->requireEnv('GA_TRACKING_ID');
30+
3131
$app = require __DIR__ . '/../app.php';
32-
$app['GA_TRACKING_ID'] = getenv('GA_TRACKING_ID');
33-
return $app;
34-
}
3532

36-
public function testIndex()
37-
{
3833
// Access the modules app top page.
39-
$client = $this->client;
40-
$crawler = $client->request('GET', '/');
41-
$this->assertTrue($client->getResponse()->isOk());
42-
$this->assertEquals(1, $crawler->filter(
43-
'html:contains("returned 200")')->count());
34+
$request = (new RequestFactory)->createRequest('GET', '/');
35+
$response = $app->handle($request);
36+
$this->assertEquals(200, $response->getStatusCode());
37+
$body = (string) $response->getBody();
38+
$this->assertStringContainsString('returned 200', $body);
4439
}
4540
}

appengine/flexible/datastore/app.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,34 @@
1616
*/
1717

1818
use Google\Cloud\Datastore\DatastoreClient;
19-
use Silex\Application;
20-
use Symfony\Component\HttpFoundation\Request;
21-
use Symfony\Component\HttpFoundation\Response;
19+
use Psr\Http\Message\ServerRequestInterface as Request;
20+
use Psr\Http\Message\ResponseInterface as Response;
21+
use RKA\Middleware\IpAddress;
22+
use Slim\Factory\AppFactory;
2223

23-
// create the Silex application
24-
$app = new Application();
24+
// Create App
25+
$app = AppFactory::create();
26+
27+
// Display errors
28+
$app->addErrorMiddleware(true, true, true);
29+
30+
// Add IP address middleware
31+
$checkProxyHeaders = true;
32+
$trustedProxies = ['10.0.0.1', '10.0.0.2'];
33+
$app->add(new IpAddress($checkProxyHeaders, $trustedProxies));
34+
35+
$app->get('/', function (Request $request, Response $response) {
36+
$projectId = getenv('GCLOUD_PROJECT');
37+
if (empty($projectId)) {
38+
$response->getBody()->write('Set the GCLOUD_PROJECT environment variable to run locally');
39+
return $response;
40+
}
2541

26-
$app['datastore'] = function () use ($app) {
27-
$projectId = $app['project_id'];
2842
# [START gae_flex_datastore_client]
2943
$datastore = new DatastoreClient([
3044
'projectId' => $projectId
3145
]);
3246
# [END gae_flex_datastore_client]
33-
return $datastore;
34-
};
35-
36-
$app->get('/', function (Application $app, Request $request) {
37-
if (empty($app['project_id'])) {
38-
return 'Set the GCLOUD_PROJECT environment variable to run locally';
39-
}
40-
/** @var \Google_Service_Datastore $datastore */
41-
$datastore = $app['datastore'];
4247

4348
// determine the user's IP
4449
$user_ip = get_user_ip($request);
@@ -68,13 +73,16 @@
6873
}
6974
# [END gae_flex_datastore_query]
7075
array_unshift($visits, "Last 10 visits:");
71-
return new Response(implode("\n", $visits), 200,
72-
['Content-Type' => 'text/plain']);
76+
$response->getBody()->write(implode("\n", $visits));
77+
78+
return $response
79+
->withStatus(200)
80+
->withHeader('Content-Type', 'text/plain');
7381
});
7482

7583
function get_user_ip(Request $request)
7684
{
77-
$ip = $request->GetClientIp();
85+
$ip = $request->getAttribute('ip_address');
7886
// Keep only the first two octets of the IP address.
7987
$octets = explode($separator = ':', $ip);
8088
if (count($octets) < 2) { // Must be ip4 address
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"require": {
3-
"silex/silex": "^2.3",
4-
"google/cloud-datastore": "^1.0"
3+
"google/cloud-datastore": "^1.0",
4+
"slim/slim": "^4.0",
5+
"slim/psr7": "^1.3",
6+
"akrabat/ip-address-middleware": "^2.0"
57
}
68
}

appengine/flexible/datastore/index.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@
2323

2424
// Run the app!
2525
// use "gcloud app deploy"
26-
$app['debug'] = true;
27-
$app['project_id'] = getenv('GCLOUD_PROJECT');
2826
$app->run();

appengine/flexible/datastore/test/LocalTest.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,23 @@
1616
*/
1717
namespace Google\Cloud\Test;
1818

19-
use Silex\WebTestCase;
19+
use PHPUnit\Framework\TestCase;
20+
use Google\Cloud\TestUtils\TestTrait;
21+
use Slim\Psr7\Factory\RequestFactory;
2022

21-
class LocalTest extends WebTestCase
23+
class LocalTest extends TestCase
2224
{
23-
public function setUp(): void
24-
{
25-
parent::setUp();
26-
$this->client = $this->createClient();
27-
}
25+
use TestTrait;
2826

29-
public function createApplication()
27+
public function testIndex()
3028
{
3129
$app = require __DIR__ . '/../app.php';
32-
if (!$projectId = getenv('GCLOUD_PROJECT')) {
33-
$this->markTestSkipped('Must set GCLOUD_PROJECT');
34-
}
35-
$app['project_id'] = $projectId;
36-
return $app;
37-
}
3830

39-
public function testIndex()
40-
{
4131
// Access the modules app top page.
42-
$client = $this->client;
43-
$client->request('GET', '/');
44-
$this->assertTrue($client->getResponse()->isOk());
45-
$text = $client->getResponse()->getContent();
32+
$request = (new RequestFactory)->createRequest('GET', '/');
33+
$response = $app->handle($request);
34+
$this->assertEquals(200, $response->getStatusCode());
35+
$text = (string) $response->getBody();
4636
$this->assertStringContainsString("Last 10 visits:", $text);
4737
}
4838
}

appengine/flexible/drupal8/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"drush/drush": "^8.1"
3+
"drush/drush": "^10.0"
44
},
55
"require-dev": {
66
"guzzlehttp/guzzle": "^6.3",
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"require": {
3-
"silex/silex": "^2.3"
4-
},
5-
"require-dev": {
6-
"symfony/browser-kit": "^4.4",
7-
"symfony/http-kernel": "^4.4"
3+
"slim/slim": "^4.0",
4+
"slim/psr7": "^1.3"
85
}
96
}

appengine/flexible/helloworld/test/ControllersTest.php renamed to appengine/flexible/helloworld/test/LocalTest.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,33 @@
1818

1919
namespace Google\Cloud\Samples\Bookshelf;
2020

21-
use Silex\WebTestCase;
21+
use PHPUnit\Framework\TestCase;
22+
use Google\Cloud\TestUtils\TestTrait;
23+
use Slim\Psr7\Factory\RequestFactory;
2224

23-
/**
24-
* Test for application controllers
25-
*/
26-
class ControllersTest extends WebTestCase
25+
class LocalTest extends TestCase
2726
{
28-
public function createApplication()
29-
{
30-
$app = require __DIR__ . '/../web/index.php';
31-
$app['debug'] = true;
32-
unset($app['exception_handler']);
33-
34-
return $app;
35-
}
27+
use TestTrait;
3628

3729
public function testTopPage()
3830
{
39-
$client = $this->createClient();
40-
$crawlerexport = $client->request('GET', '/');
41-
$resp = $client->getResponse();
42-
$this->assertTrue($resp->isOk());
43-
$this->assertStringContainsString('Hello World', $resp->getContent());
31+
$app = require __DIR__ . '/../web/index.php';
32+
33+
$request = (new RequestFactory)->createRequest('GET', '/');
34+
$response = $app->handle($request);
35+
$this->assertEquals(200, $response->getStatusCode());
36+
$body = (string) $response->getBody();
37+
$this->assertStringContainsString('Hello World', $body);
4438
}
4539

4640
public function testGoodbye()
4741
{
48-
$client = $this->createClient();
49-
$crawlerexport = $client->request('GET', '/goodbye');
50-
$resp = $client->getResponse();
51-
$this->assertTrue($resp->isOk());
52-
$this->assertStringContainsString('Goodbye World', $resp->getContent());
42+
$app = require __DIR__ . '/../web/index.php';
43+
44+
$request = (new RequestFactory)->createRequest('GET', '/goodbye');
45+
$response = $app->handle($request);
46+
$this->assertEquals(200, $response->getStatusCode());
47+
$body = (string) $response->getBody();
48+
$this->assertStringContainsString('Goodbye World', $body);
5349
}
5450
}

appengine/flexible/helloworld/web/index.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,24 @@
1919
// [START appengine_flex_helloworld_index_php]
2020
require_once __DIR__ . '/../vendor/autoload.php';
2121

22-
$app = new Silex\Application();
22+
use Psr\Http\Message\ServerRequestInterface as Request;
23+
use Psr\Http\Message\ResponseInterface as Response;
24+
use Slim\Factory\AppFactory;
2325

24-
$app->get('/', function () {
25-
return 'Hello World';
26+
// Create App
27+
$app = AppFactory::create();
28+
29+
// Display errors
30+
$app->addErrorMiddleware(true, true, true);
31+
32+
$app->get('/', function (Request $request, Response $response) {
33+
$response->getBody()->write('Hello World');
34+
return $response;
2635
});
2736

28-
$app->get('/goodbye', function () {
29-
return 'Goodbye World';
37+
$app->get('/goodbye', function (Request $request, Response $response) {
38+
$response->getBody()->write('Goodbye World');
39+
return $response;
3040
});
3141

3242
// @codeCoverageIgnoreStart

0 commit comments

Comments
 (0)