akrabat commented on code in PR #122:
URL: 
https://github.com/apache/openwhisk-runtime-php/pull/122#discussion_r952273151


##########
core/php8.1Action/runner.php:
##########
@@ -0,0 +1,91 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// open fd/3 as that's where we send the result
+$fd3 = fopen('php://fd/3', 'wb');
+
+// Register a shutdown function so that we can fail gracefully when a fatal 
error occurs
+register_shutdown_function(static function () use ($fd3) {
+    $error = error_get_last();
+    if ($error && in_array($error['type'], [E_ERROR, E_CORE_ERROR, 
E_COMPILE_ERROR, E_USER_ERROR], true)) {
+        file_put_contents('php://stderr', "An error occurred running the 
action.\n");
+        fwrite($fd3, "An error occurred running the action.\n");
+    }
+    fclose($fd3);
+});
+
+require 'vendor/autoload.php';
+require 'index.php';
+
+// retrieve main function
+$__functionName = $argv[1] ?? 'main';
+
+
+// read stdin
+while ($f = fgets(STDIN)) {
+    // call the function
+    $data = json_decode($f ?? '', true);
+    if (!is_array($data)) {
+        $data = [];
+    }
+
+    // convert all parameters other than value to environment variables
+    foreach ($data as $key => $value) {
+        if ($key !== 'value') {
+            $envKeyName = '__OW_' . strtoupper($key);
+            $_ENV[$envKeyName] = $value;
+            putenv($envKeyName . '=' . $value);
+        }
+    }
+
+    $values = $data['value'] ?? [];
+    try {
+        $result = $__functionName($values);
+
+        // convert result to an array if we can
+        if (is_object($result)) {
+            if (method_exists($result, 'getArrayCopy')) {
+                $result = $result->getArrayCopy();
+            } elseif ($result instanceof stdClass) {
+                $result = (array)$result;
+            }
+        } elseif ($result === null) {
+            $result = [];
+        }
+
+        // process the result
+        if (!is_array($result)) {
+            file_put_contents('php://stderr', 'Result must be an array but has 
type "'
+                . gettype($result) . '": ' . $result);
+            file_put_contents('php://stdout', 'The action did not return a 
dictionary or array.');
+            $result = (string)$result;
+        } else {
+            $result = json_encode((object)$result);

Review Comment:
   Add comment before this line:
   
   ```
   // cast result to an object for json_encode to ensure that an empty array 
becomes "{}
   ```



##########
core/php8.1Action/runner.php:
##########
@@ -0,0 +1,91 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// open fd/3 as that's where we send the result
+$fd3 = fopen('php://fd/3', 'wb');
+
+// Register a shutdown function so that we can fail gracefully when a fatal 
error occurs
+register_shutdown_function(static function () use ($fd3) {
+    $error = error_get_last();
+    if ($error && in_array($error['type'], [E_ERROR, E_CORE_ERROR, 
E_COMPILE_ERROR, E_USER_ERROR], true)) {
+        file_put_contents('php://stderr', "An error occurred running the 
action.\n");
+        fwrite($fd3, "An error occurred running the action.\n");
+    }
+    fclose($fd3);
+});
+
+require 'vendor/autoload.php';
+require 'index.php';
+
+// retrieve main function
+$__functionName = $argv[1] ?? 'main';
+
+
+// read stdin
+while ($f = fgets(STDIN)) {
+    // call the function
+    $data = json_decode($f ?? '', true);
+    if (!is_array($data)) {
+        $data = [];
+    }
+
+    // convert all parameters other than value to environment variables
+    foreach ($data as $key => $value) {
+        if ($key !== 'value') {
+            $envKeyName = '__OW_' . strtoupper($key);
+            $_ENV[$envKeyName] = $value;
+            putenv($envKeyName . '=' . $value);
+        }
+    }
+
+    $values = $data['value'] ?? [];
+    try {
+        $result = $__functionName($values);
+
+        // convert result to an array if we can
+        if (is_object($result)) {
+            if (method_exists($result, 'getArrayCopy')) {
+                $result = $result->getArrayCopy();
+            } elseif ($result instanceof stdClass) {
+                $result = (array)$result;
+            }
+        } elseif ($result === null) {
+            $result = [];
+        }
+
+        // process the result
+        if (!is_array($result)) {
+            file_put_contents('php://stderr', 'Result must be an array but has 
type "'
+                . gettype($result) . '": ' . $result);
+            file_put_contents('php://stdout', 'The action did not return a 
dictionary or array.');
+            $result = (string)$result;
+        } else {
+            $result = json_encode((object)$result);
+        }
+    } catch (Throwable $e) {
+        file_put_contents('php://stderr', (string)$e);
+        $result = 'An error occurred running the action.';
+    }
+
+    // ensure that the sentinels will be on their own lines
+    file_put_contents('php://stderr', "\n");
+    file_put_contents('php://stdout', "\n");
+
+    // cast result to an object for json_encode to ensure that an empty array 
becomes "{}" & send to fd/3

Review Comment:
   This comment is wrong as it doesn't do the cast here. Should be:
   
   ```
   // send result to fd/3
   ```



##########
core/php8.1Action/Dockerfile:
##########
@@ -0,0 +1,114 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# build go proxy from source
+FROM golang:1.18 AS builder_source
+ARG GO_PROXY_GITHUB_USER=apache
+ARG GO_PROXY_GITHUB_BRANCH=master
+RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
+   https://github.com/${GO_PROXY_GITHUB_USER}/openwhisk-runtime-go /src ;\
+   cd /src ; env GO111MODULE=on CGO_ENABLED=0 go build main/proxy.go && \
+   mv proxy /bin/proxy
+
+# or build it from a release
+FROM golang:1.18 AS builder_release
+ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
+RUN curl -sL \
+  
https://github.com/apache/openwhisk-runtime-go/archive/{$GO_PROXY_RELEASE_VERSION}.tar.gz\
+  | tar xzf -\
+  && cd openwhisk-runtime-go-*/main\
+  && GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
+
+FROM php:8.1-cli-bullseye
+
+# select the builder to use
+ARG GO_PROXY_BUILD_FROM=release
+
+# install PHP extensions
+RUN apt-get -y update \
+    && apt-get -y install --no-install-recommends \
+      unzip \
+      libfreetype6 \
+      libicu67 \
+      libjpeg62-turbo \
+      libpng16-16 \
+      libssl1.1 \
+      libxml2 \
+      libzip4 \
+      libpq5 \
+      zip \
+      libfreetype6-dev \
+      libicu-dev \
+      libjpeg-dev \
+      libpng-dev \
+      libssl-dev \
+      libxml2-dev \
+      libzip-dev \
+      postgresql-server-dev-13 \
+    \
+    && docker-php-ext-install \
+      bcmath \
+      gd \
+      intl \
+      mysqli \
+      opcache \
+      pdo_mysql \
+      pdo_pgsql \
+      soap \
+      zip \
+    \
+    && mkdir -p /usr/src/php/ext/mongodb \
+    && curl -fsSL https://pecl.php.net/get/mongodb-1.14.0 | tar xvz -C 
"/usr/src/php/ext/mongodb" --strip 1 \
+    && docker-php-ext-install -j$(nproc) mongodb \
+    \
+    && apt-get purge -y --auto-remove $PHPIZE_DEPS \
+    # && apt-get purge -y --auto-remove libclang-common-7-dev clang-7 llvm-7 
llvm-7-dev \

Review Comment:
   Can we delete this commented out line?



##########
README.md:
##########
@@ -93,6 +104,10 @@ wskdev fresh -t local-php
 
 To use as docker action push to your own dockerhub account
 ```
+docker tag whisk/php8.0Action $user_prefix/action-php-v8.1

Review Comment:
   `s/php8.0Action/php8.1Action/` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@openwhisk.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to