From 194678e939f7a24b37625dd80d08398027842db3 Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Thu, 25 Nov 2021 06:44:23 +0000 Subject: [PATCH] Update workflows --- .github/workflows/ci.yml | 18 ++++++++++-------- .github/workflows/phpdoc.yml | 4 +++- .github/workflows/update-satis.yml | 8 ++------ src/Middleware/Gzip.php | 2 +- src/RampageRequestHandler.php | 16 ++++++++++++---- src/RequestBuilder.php | 9 +++++++++ src/ResponseWriterInterface.php | 2 +- src/ResponseWriterWeb.php | 10 ++++------ src/Runner.php | 2 +- 9 files changed, 43 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6ee31d..4db260e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,12 +8,12 @@ on: push: branches: - master - - maintaina-composerfixed + - main - FRAMEWORK_6_0 pull_request: branches: - master - - maintaina-composerfixed + - main - FRAMEWORK_6_0 @@ -27,7 +27,7 @@ jobs: strategy: matrix: operating-system: ['ubuntu-20.04'] - php-versions: ['7.4', '8.0'] + php-versions: ['7.4', '8.0', 'latest'] phpunit-versions: ['latest', '9.5'] steps: - name: Setup github ssh key @@ -39,18 +39,20 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - extensions: bcmath, ctype, curl, dom, gd, gettext, iconv, imagick, json, ldap, mbstring, mysql, opcache, openssl, pcntl, pdo, posix, redis, soap, sockets, sqlite, tokenizer, xmlwriter + extensions: bcmath, ctype, curl, dom, gd, fileinfo, gettext, iconv, imagick, json, ldap, mbstring, mysql, opcache, openssl, pcntl, pdo, posix, redis, soap, sockets, sqlite, tokenizer, xmlwriter ini-values: post_max_size=512M, max_execution_time=360 coverage: xdebug - tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}, composer:v2 + tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}, composer:v2, phpstan - name: Setup Github Token as composer credential run: composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }} - name: Install horde/test dependency and other dependencies run: | + ## For unclear reasons, github action fails randomly if we do not install before we require. COMPOSER_ROOT_VERSION=dev-FRAMEWORK_6_0 composer config minimum-stability dev COMPOSER_ROOT_VERSION=dev-FRAMEWORK_6_0 composer install - - name: Redo install due to many fails - run: | - COMPOSER_ROOT_VERSION=dev-FRAMEWORK_6_0 composer install + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: run phpunit run: phpunit --bootstrap test/bootstrap.php + - name: run phpstan + run: phpstan analyze src/ --level 8 diff --git a/.github/workflows/phpdoc.yml b/.github/workflows/phpdoc.yml index 67c965d..f192303 100644 --- a/.github/workflows/phpdoc.yml +++ b/.github/workflows/phpdoc.yml @@ -7,6 +7,8 @@ on: # Triggers the workflow on push or pull request events but only for the master branch push: branches: + - master + - maintaina-composerfixed - FRAMEWORK_6_0 # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -58,7 +60,7 @@ jobs: echo "Creating UUT related dir in docu repo" mkdir -p $UUT_DIR/phpdoc-git/${GITHUB_REF##*/}/${REPO}/ ## TODO: check for and include lib, src, app (if they exist) but not test or script dirs - $BIN_DIR/phpdocumentor -d $UUT_DIR/src/ -t "${UUT_DIR}/phpdoc-git/${GITHUB_REF##*/}/${REPO}/" + $BIN_DIR/phpdocumentor -d $UUT_DIR/lib/ -d $UUT_DIR/src/ -d $UUT_DIR/app/ -t "${UUT_DIR}/phpdoc-git/${GITHUB_REF##*/}/${REPO}/" cd ${UUT_DIR}/phpdoc-git git add "${GITHUB_REF##*/}/${REPO}" php indexer.php ${GITHUB_REF##*/} $REPO diff --git a/.github/workflows/update-satis.yml b/.github/workflows/update-satis.yml index eaedff5..5049bd0 100644 --- a/.github/workflows/update-satis.yml +++ b/.github/workflows/update-satis.yml @@ -52,12 +52,8 @@ jobs: export WORK_DIR=/home/runner/ export BIN_DIR="${WORK_DIR}/bin" composer create-project composer/satis:dev-main - php satis/bin/satis build -vvv maintaina-com.github.io/satis.json maintaina-com.github.io/ horde/http_server + php satis/bin/satis build -vvv maintaina-com.github.io/satis.json maintaina-com.github.io/ horde/${REPO,,} cd maintaina-com.github.io git add include/ index.html p2/ packages.json - git commit -m "Update for horde/http_server" + git commit -m "Update for horde/${REPO,,}" git push - - - - diff --git a/src/Middleware/Gzip.php b/src/Middleware/Gzip.php index f39bc4c..05b8d5a 100644 --- a/src/Middleware/Gzip.php +++ b/src/Middleware/Gzip.php @@ -63,7 +63,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface * multi-byte chars as single bytes so we need to treat the string like its * 8-bit encoded to get an accurate byte count. */ - protected function _byteCount($string) + protected function _byteCount(string $string): int { if (ini_get('mbstring.func_overload') > 0) { return mb_strlen($string, '8bit'); diff --git a/src/RampageRequestHandler.php b/src/RampageRequestHandler.php index 37a8c1c..5776a84 100644 --- a/src/RampageRequestHandler.php +++ b/src/RampageRequestHandler.php @@ -3,7 +3,7 @@ use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\MiddlewareInterface; -use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; @@ -42,6 +42,14 @@ class RampageRequestHandler implements RequestHandlerInterface private ?RequestHandlerInterface $payloadHandler; + /** + * Constructor + * + * @param ResponseFactoryInterface $responseFactory + * @param StreamFactoryInterface $streamFactory + * @param MiddlewareInterface[] $middlewares + * @param RequestHandlerInterface|null $payloadHandler + */ public function __construct( ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory, @@ -60,7 +68,7 @@ public function __construct( /** * Add another middleware to the queue just before the payload handler */ - public function addMiddleware(MiddlewareInterface $middleware) + public function addMiddleware(MiddlewareInterface $middleware): void { $this->middlewares[] = $middleware; } @@ -68,7 +76,7 @@ public function addMiddleware(MiddlewareInterface $middleware) /** * Configure the payload handler */ - public function setPayloadHandler(RequestHandlerInterface $handler) + public function setPayloadHandler(RequestHandlerInterface $handler): void { $this->payloadHandler = $handler; } @@ -89,7 +97,7 @@ public function nextMiddleware(): ?MiddlewareInterface * * Finally the we will return a response ourselves. */ - public function handle(RequestInterface $request): ResponseInterface + public function handle(ServerRequestInterface $request): ResponseInterface { $middleware = $this->nextMiddleware(); if ($middleware) { diff --git a/src/RequestBuilder.php b/src/RequestBuilder.php index bc48d20..f7ae7e6 100644 --- a/src/RequestBuilder.php +++ b/src/RequestBuilder.php @@ -45,6 +45,9 @@ public function withGlobalVariables(): self } else { $scheme = 'https'; } + } else { + // Default to https + $scheme = 'https'; } $host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME']; $queryString = $_SERVER['QUERY_STRING'] ?? ''; @@ -75,6 +78,12 @@ public function withGlobalVariables(): self return $this; } + /** + * Add headers from list + * + * @param mixed[] $headers + * @return self + */ public function withHeaders(array $headers): self { foreach ($headers as $header => $value) { diff --git a/src/ResponseWriterInterface.php b/src/ResponseWriterInterface.php index 3c9e6da..760f4f1 100644 --- a/src/ResponseWriterInterface.php +++ b/src/ResponseWriterInterface.php @@ -8,5 +8,5 @@ interface ResponseWriterInterface /** * Output the HTTP Response to STDOUT */ - public function writeResponse(ResponseInterface $response); + public function writeResponse(ResponseInterface $response): void; } diff --git a/src/ResponseWriterWeb.php b/src/ResponseWriterWeb.php index ef5ab15..cad05d4 100644 --- a/src/ResponseWriterWeb.php +++ b/src/ResponseWriterWeb.php @@ -25,7 +25,7 @@ */ class ResponseWriterWeb implements ResponseWriterInterface { - public function writeResponse(ResponseInterface $response) + public function writeResponse(ResponseInterface $response): void { header( sprintf( @@ -39,10 +39,8 @@ public function writeResponse(ResponseInterface $response) header($key . ': ' . $response->getHeaderLine($key)); } $body = $response->getBody(); - if (is_resource($body)) { - stream_copy_to_stream($body, fopen('php://output', 'a')); - } else { - echo $body; - } + // For now, disable outputting the stream via stream copying + // We would need to implement a stream wrapper first + echo $body; } } diff --git a/src/Runner.php b/src/Runner.php index f9ba2f5..da19f2a 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -22,7 +22,7 @@ public function __construct(RequestHandlerInterface $handler, ResponseWriterInte $this->responseWriter = $responseWriter; } - public function run(ServerRequestInterface $request) + public function run(ServerRequestInterface $request): void { $response = $this->handler->handle($request); $this->responseWriter->writeResponse($response);