Skip to content

Commit 7ac2b79

Browse files
authored
Add support for Google Cloud (#32)
* Add support for Google Cloud * cs * Added "tests"
0 parents  commit 7ac2b79

File tree

8 files changed

+132
-0
lines changed

8 files changed

+132
-0
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [nyholm]

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
composer.lock

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 Tobias Nyholm
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Google Cloud Runtime with nyholm/psr7
2+
3+
A runtime for [Google Cloud](https://cloud.google.com/).
4+
5+
## Installation
6+
7+
This runtime layer is special. It includes a `router.php` to enable the use of
8+
Symfony Runtime component. You need to install this package **and** the runtime you
9+
want to use.
10+
11+
To use with native or Symfony application.
12+
13+
```
14+
composer require runtime/google-cloud symfony/runtime
15+
```
16+
17+
If you want to use it with PSR-7.
18+
```
19+
composer require runtime/google-cloud runtime/psr-nyholm-laminas
20+
```
21+
22+
## Usage
23+
24+
Define the environment variable `FUNCTION_SOURCE`.
25+
26+
```
27+
# Default value
28+
FUNCTION_SOURCE=index.php
29+
```
30+
31+
Note that Google Cloud **requires** you to have an index.php file. If you are running
32+
Symfony you probably want to define `FUNCTION_SOURCE=public/index.php` but you
33+
still need to create an `index.php`.
34+
35+
```php
36+
<?php
37+
// index.php
38+
// This file is needed for google cloud
39+
```
40+
41+

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "runtime/google-cloud",
3+
"type": "library",
4+
"description": "Google Cloud runtime",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Tobias Nyholm",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"symfony/runtime": "5.x-dev"
14+
},
15+
"require-dev": {
16+
"symfony/phpunit-bridge": "^5.2"
17+
},
18+
"minimum-stability": "dev",
19+
"prefer-stable": true,
20+
"bin": [
21+
"router.php"
22+
]
23+
}

phpunit.xml.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4+
backupGlobals="false"
5+
colors="true"
6+
bootstrap="vendor/autoload.php"
7+
failOnRisky="true"
8+
failOnWarning="true"
9+
>
10+
<php>
11+
<ini name="error_reporting" value="-1"/>
12+
</php>
13+
<testsuites>
14+
<testsuite name="Test Suite">
15+
<directory>./tests</directory>
16+
<directory suffix=".phpt">./tests/phpt</directory>
17+
</testsuite>
18+
</testsuites>
19+
</phpunit>

router.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* Determine the function source file to load.
5+
*/
6+
$documentRoot = __DIR__.'/../../../';
7+
if ($functionSource = $_SERVER['FUNCTION_SOURCE'] ?? null) {
8+
if (0 !== strpos($functionSource, '/')) {
9+
// Make the path relative
10+
$relativeSource = $documentRoot.$functionSource;
11+
if (!file_exists($relativeSource)) {
12+
throw new RuntimeException(sprintf('Unable to load function from "%s"', $relativeSource));
13+
}
14+
require_once $_SERVER['SCRIPT_FILENAME'] = $relativeSource;
15+
} else {
16+
require_once $_SERVER['SCRIPT_FILENAME'] = $functionSource;
17+
}
18+
} elseif (file_exists($defaultSource = $documentRoot.'index.php')) {
19+
// Default to "index.php" in the root of the application.
20+
require_once $_SERVER['SCRIPT_FILENAME'] = $defaultSource;
21+
} else {
22+
throw new RuntimeException('Did not find your index.php. Please define environment variable "FUNCTION_SOURCE".');
23+
}

tests/.gitignore

Whitespace-only changes.

0 commit comments

Comments
 (0)