-
-def send_api_query_php(endpoint, params, context):
- env = dict(BASE_SERVER_ENV)
- env['QUERY_STRING'] = urlencode(params)
-
- env['SCRIPT_NAME'] = f'/{endpoint}.php'
- env['REQUEST_URI'] = f"{env['SCRIPT_NAME']}?{env['QUERY_STRING']}"
- env['CONTEXT_DOCUMENT_ROOT'] = os.path.join(context.nominatim.website_dir.name, 'website')
- env['SCRIPT_FILENAME'] = os.path.join(env['CONTEXT_DOCUMENT_ROOT'],
- f'{endpoint}.php')
-
- LOG.debug("Environment:" + json.dumps(env, sort_keys=True, indent=2))
-
- if hasattr(context, 'http_headers'):
- env.update(context.http_headers)
-
- cmd = ['/usr/bin/env', 'php-cgi', '-f']
- if context.nominatim.code_coverage_path:
- env['XDEBUG_MODE'] = 'coverage'
- env['COV_SCRIPT_FILENAME'] = env['SCRIPT_FILENAME']
- env['COV_PHP_DIR'] = context.nominatim.src_dir
- env['COV_TEST_NAME'] = f"{context.scenario.filename}:{context.scenario.line}"
- env['SCRIPT_FILENAME'] = \
- os.path.join(os.path.split(__file__)[0], 'cgi-with-coverage.php')
- cmd.append(env['SCRIPT_FILENAME'])
- env['PHP_CODE_COVERAGE_FILE'] = context.nominatim.next_code_coverage_file()
- else:
- cmd.append(env['SCRIPT_FILENAME'])
-
- for k,v in params.items():
- cmd.append(f"{k}={v}")
-
- outp, err = run_script(cmd, cwd=context.nominatim.website_dir.name, env=env)
-
- assert len(err) == 0, f"Unexpected PHP error: {err}"
-
- if outp.startswith('Status: '):
- status = int(outp[8:11])
- else:
- status = 200
-
- content_start = outp.find('\r\n\r\n')
-
- return outp[content_start + 4:], status
-