Created
September 13, 2023 02:45
-
-
Save tobsn/ced11b14ff5a752f7d81d7852ad9a3b5 to your computer and use it in GitHub Desktop.
digitalocean php serverless function hardcoded local simulation & composer base config incl mongodb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"config": { | |
"platform": { | |
"php": "8.0.28", | |
"ext-mongodb": "1.9.0RC1" | |
} | |
}, | |
"require": { | |
"mongodb/mongodb": "^1.4", | |
}, | |
"require-dev": { | |
"phpunit/phpunit": "^9.6" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getallheader(){$headers = getallheaders();foreach($headers as $key=>$value){unset($headers[$key]);$headers[strtolower($key)]=$value;}ksort($headers);return $headers;} | |
$_SERVER['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'] ?? 'GET'; | |
$data = [ | |
'__ow_headers' => getallheader(), | |
'__ow_method' => strtolower( $_SERVER['REQUEST_METHOD'] ), | |
'__ow_path' => '' | |
]; | |
$data['http'] = [ | |
'headers' => $data['__ow_headers'], | |
'method' => strtoupper( $data['__ow_method'] ), | |
'path' => $data['__ow_path'] | |
]; | |
if( count( $_GET ) > 0 ) { | |
$data['__ow_query'] = $data['http']['queryString'] = http_build_query( $_GET ); | |
} | |
if( $_SERVER['REQUEST_METHOD'] === 'POST' ) { | |
if( strpos( $data['http']['headers']['content-type'], 'x-www-form-urlencoded' ) !== false ) { | |
$data['__ow_body'] = $data['http']['body'] = http_build_query( $_POST ); | |
$data['__ow_isBase64Encoded'] = $data['http']['isBase64Encoded'] = false; | |
} | |
else if( strpos( $data['http']['headers']['content-type'], 'multipart/form-data' ) !== false ) { | |
$data['__ow_body'] = $data['http']['body'] = base64_encode( file_get_contents('php://input') ); | |
$data['__ow_isBase64Encoded'] = $data['http']['isBase64Encoded'] = true; | |
} | |
} | |
require_once('index.php'); | |
die( json_encode( main( $data )['body'] ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment