Skip to content

Commit cbd2cb5

Browse files
authored
First Round of Changes (#1)
* removes builders directory * updates the README * adds a sample Dockerfile * adds tests and test suites * adds composer in root * misc updates to classes and router.php
1 parent 01d1a6c commit cbd2cb5

33 files changed

+676
-415
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.gitattributes export-ignore
2+
/tests export-ignore

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
build/
3+
composer.phar
4+
composer.lock
5+
vendor/
6+
.idea/
7+
/.php_cs.cache
8+
*.iml

.php_cs.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
return PhpCsFixer\Config::create()
4+
->setRules([
5+
'@PSR2' => true,
6+
'concat_space' => ['spacing' => 'one'],
7+
'no_unused_imports' => true,
8+
'method_argument_space' => false,
9+
])
10+
->setFinder(
11+
PhpCsFixer\Finder::create()
12+
->in(__DIR__)
13+
->exclude(__DIR__.'/vendor')
14+
)
15+
;

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
language: php
2+
3+
branches:
4+
only: [master]
5+
6+
matrix:
7+
include:
8+
- php: 7.1
9+
- php: 7.2
10+
- php: 7.3
11+
- php: 7.4
12+
13+
env:
14+
global:
15+
- COMPOSER_BIN_DIR=$(composer global config bin-dir --absolute)
16+
17+
before_install:
18+
- composer install
19+
- composer global require friendsofphp/php-cs-fixer:^2
20+
21+
script:
22+
- $COMPOSER_BIN_DIR/php-cs-fixer fix --dry-run --diff .
23+
- $COMPOSER_BIN_DIR/phpunit -v

README.md

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ different environments, including:
1515
The framework allows you to go from:
1616

1717
```php
18-
function helloWorld() {
19-
return "Hello, World" . PHP_EOL;
18+
function helloHttp() {
19+
return "Hello World from PHP HTTP function!" . PHP_EOL;
2020
};
2121
```
2222

2323
To:
2424

2525
```sh
2626
curl http://my-url
27-
# Output: Hello, World
27+
# Output: "Hello World from PHP HTTP function!"
2828
```
2929

3030
All without needing to worry about writing an HTTP server or complicated request
@@ -48,54 +48,68 @@ Add the Functions Framework to your `composer.json` file using `composer`.
4848
composer install google/cloud-functions-framework
4949
```
5050

51-
# Quickstart: Hello, World on your local machine
51+
# Quickstart: Run your function locally on your local machine
5252

5353
Create an `index.php` file with the following contents:
5454

5555
```php
56-
function helloWorld() {
57-
return "Hello, World" . PHP_EOL;
56+
function helloHttp() {
57+
return "Hello World from PHP HTTP function!" . PHP_EOL;
5858
};
5959
```
6060

6161
Run the following commands:
6262

6363
```sh
64-
export FUNCTION_TARGET="httpFunction"
65-
export FUNCTION_SIGNATURE_TYPE="http"
66-
php -S localhost:8080 vendor/google/cloud-functions-framework/invoker/router.php
64+
export FUNCTION_TARGET=helloHttp
65+
export FUNCTION_SIGNATURE_TYPE=http
66+
export FUNCTION_SOURCE=index.php
67+
php -S localhost:8080 vendor/bin/router.php
6768
```
6869

69-
Open `http://localhost:8080/` in your browser and see *Hello, World*.
70+
Open `http://localhost:8080/` in your browser and see *Hello World...*.
7071

7172

72-
# Quickstart: Set up a new project
73+
# Quickstart: Run your function in a container
7374

7475
Create an `index.php` file with the following contents:
7576

7677
```php
77-
function helloWorld() {
78-
return "Hello, World" . PHP_EOL;
78+
function helloHttp() {
79+
return "Hello World from PHP HTTP function!" . PHP_EOL;
7980
};
8081
```
8182

82-
To run a function locally, first create a `composer.json` file using `composer init`:
83+
Now install the Functions Framework:
8384

8485
```sh
85-
composer init
86+
composer install google-cloud/functions-framework
8687
```
8788

88-
Now install the Functions Framework:
89+
Build the container using the example Dockerfile:
8990

90-
```sh
91-
composer install google-cloud/functions-framework
91+
```
92+
docker build . \
93+
-f vendor/google/cloud-functions/framework/examples/hello/Dockerfile \
94+
-t my-cloud-function
95+
```
96+
97+
Run the cloud functions framework container:
98+
99+
```
100+
docker run -p 8080:8080 \
101+
-e FUNCTION_TARGET=helloHttp \
102+
-e FUNCTION_SIGNATURE_TYPE=http \
103+
-e FUNCTION_SOURCE=index.php \
104+
my-cloud-function
92105
```
93106

94-
Send requests to this function using `curl` from another terminal window:
107+
Open `http://localhost:8080/` in your browser and see *Hello World...*, or
108+
send requests to this function using `curl` from another terminal window:
95109

96110
```sh
97111
curl localhost:8080
98-
# Output: Hello, World
112+
# Output: Hello World from PHP HTTP function!
99113
```
100114

101115
# Run your function on serverless platforms

builders/php/build-template.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

builders/php/converter/Dockerfile

Lines changed: 0 additions & 23 deletions
This file was deleted.

builders/php/converter/converter.go

Lines changed: 0 additions & 123 deletions
This file was deleted.

composer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "google/cloud-functions-framework",
3+
"description": "Google Cloud Functions Framework for PHP",
4+
"require": {
5+
"symfony/http-foundation": "^4.1"
6+
},
7+
"autoload": {
8+
"psr-4": {
9+
"Google\\CloudFunctions\\": "src"
10+
}
11+
},
12+
"require-dev": {
13+
"phpunit/phpunit": "^7.0|^8.0"
14+
},
15+
"bin": [
16+
"router.php"
17+
]
18+
}

examples/hello/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM gcr.io/gae-runtimes/php73:php73_20191020_7_3_10_RC00
2+
3+
WORKDIR /srv/
4+
5+
# NOTE: The entrypoint "/start", which starts up NGINX and PHP-FPM,
6+
# is configured by creating a `.googleconfig/app_start.json` file with the
7+
# contents:
8+
#
9+
# {"entrypointContents": "CUSTOM_ENTRYPOINT"}
10+
#
11+
# We configure it to use the `router.php` file included in this package.
12+
RUN mkdir .googleconfig && \
13+
echo '{"entrypointContents": "serve vendor/bin/router.php"}' > .googleconfig/app_start.json
14+
15+
# Copy over composer files and run "composer install"
16+
COPY composer.* ./
17+
COPY --from=composer:1 /usr/bin/composer /usr/local/bin
18+
RUN composer install --no-dev
19+
20+
# Copy over all application files
21+
COPY . .
22+
23+
# Set a runtime name (required by the base image)
24+
ENV GAE_RUNTIME php73

0 commit comments

Comments
 (0)