diff --git a/lib/classes/component.php b/lib/classes/component.php index 50877e63a39..9db0d8f6678 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -124,9 +124,14 @@ class component { 'lib/psr/http-message/src', 'lib/psr/http-factory/src', ], + \Psr\Http\Server::class => [ + "lib/psr/http-server-handler/src", + "lib/psr/http-server-middleware/src", + ], \Psr\EventDispatcher::class => 'lib/psr/event-dispatcher/src', \Psr\Clock::class => 'lib/psr/clock/src', \Psr\Container::class => 'lib/psr/container/src', + \Psr\Log::class => "lib/psr/log/src", \GuzzleHttp\Psr7::class => 'lib/guzzlehttp/psr7/src', \GuzzleHttp\Promise::class => 'lib/guzzlehttp/promises/src', \GuzzleHttp::class => 'lib/guzzlehttp/guzzle/src', diff --git a/lib/psr/http-server-handler/LICENSE b/lib/psr/http-server-handler/LICENSE new file mode 100644 index 00000000000..b71ec5dfc20 --- /dev/null +++ b/lib/psr/http-server-handler/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 PHP Framework Interoperability Group + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/psr/http-server-handler/README.md b/lib/psr/http-server-handler/README.md new file mode 100644 index 00000000000..111a9ed2e8b --- /dev/null +++ b/lib/psr/http-server-handler/README.md @@ -0,0 +1,12 @@ +HTTP Server Request Handlers for Middleware +=========================================== + +This repository holds the `RequestHandlerInterface` related to [PSR-15 (HTTP Server Request Handlers)][psr-url]. + +Note that this is not a Server Request Handler implementation of its own. It is merely the interface that describe a Server Request Handler. + +The installable [package][package-url] and [implementations][implementation-url] are listed on Packagist. + +[psr-url]: https://www.php-fig.org/psr/psr-15/ +[package-url]: https://packagist.org/packages/psr/http-server-handler +[implementation-url]: https://packagist.org/providers/psr/http-server-handler-implementation diff --git a/lib/psr/http-server-handler/composer.json b/lib/psr/http-server-handler/composer.json new file mode 100644 index 00000000000..c54b2dee822 --- /dev/null +++ b/lib/psr/http-server-handler/composer.json @@ -0,0 +1,36 @@ +{ + "name": "psr/http-server-handler", + "description": "Common interface for HTTP server-side request handler", + "keywords": [ + "psr", + "psr-7", + "psr-15", + "http-interop", + "http", + "server", + "handler", + "request", + "response" + ], + "license": "MIT", + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "require": { + "php": ">=7.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Server\\": "src/" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + } +} diff --git a/lib/psr/http-server-handler/src/RequestHandlerInterface.php b/lib/psr/http-server-handler/src/RequestHandlerInterface.php new file mode 100644 index 00000000000..83911e265b8 --- /dev/null +++ b/lib/psr/http-server-handler/src/RequestHandlerInterface.php @@ -0,0 +1,22 @@ +=7.0", + "psr/http-message": "^1.0 || ^2.0", + "psr/http-server-handler": "^1.0" + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Server\\": "src/" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + } +} diff --git a/lib/psr/http-server-middleware/src/MiddlewareInterface.php b/lib/psr/http-server-middleware/src/MiddlewareInterface.php new file mode 100644 index 00000000000..a6c14f8c729 --- /dev/null +++ b/lib/psr/http-server-middleware/src/MiddlewareInterface.php @@ -0,0 +1,25 @@ +logger = $logger; + } + + public function doSomething() + { + if ($this->logger) { + $this->logger->info('Doing work'); + } + + try { + $this->doSomethingElse(); + } catch (Exception $exception) { + $this->logger->error('Oh no!', array('exception' => $exception)); + } + + // do something useful + } +} +``` + +You can then pick one of the implementations of the interface to get a logger. + +If you want to implement the interface, you can require this package and +implement `Psr\Log\LoggerInterface` in your code. Please read the +[specification text](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) +for details. diff --git a/lib/psr/log/composer.json b/lib/psr/log/composer.json new file mode 100644 index 00000000000..879fc6f53bb --- /dev/null +++ b/lib/psr/log/composer.json @@ -0,0 +1,26 @@ +{ + "name": "psr/log", + "description": "Common interface for logging libraries", + "keywords": ["psr", "psr-3", "log"], + "homepage": "https://github.com/php-fig/log", + "license": "MIT", + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "require": { + "php": ">=8.0.0" + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "src" + } + }, + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + } +} diff --git a/lib/psr/log/src/AbstractLogger.php b/lib/psr/log/src/AbstractLogger.php new file mode 100644 index 00000000000..d60a091affa --- /dev/null +++ b/lib/psr/log/src/AbstractLogger.php @@ -0,0 +1,15 @@ +logger = $logger; + } +} diff --git a/lib/psr/log/src/LoggerInterface.php b/lib/psr/log/src/LoggerInterface.php new file mode 100644 index 00000000000..b3a24b5f7e9 --- /dev/null +++ b/lib/psr/log/src/LoggerInterface.php @@ -0,0 +1,125 @@ +log(LogLevel::EMERGENCY, $message, $context); + } + + /** + * Action must be taken immediately. + * + * Example: Entire website down, database unavailable, etc. This should + * trigger the SMS alerts and wake you up. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function alert(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::ALERT, $message, $context); + } + + /** + * Critical conditions. + * + * Example: Application component unavailable, unexpected exception. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function critical(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::CRITICAL, $message, $context); + } + + /** + * Runtime errors that do not require immediate action but should typically + * be logged and monitored. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function error(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::ERROR, $message, $context); + } + + /** + * Exceptional occurrences that are not errors. + * + * Example: Use of deprecated APIs, poor use of an API, undesirable things + * that are not necessarily wrong. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function warning(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::WARNING, $message, $context); + } + + /** + * Normal but significant events. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function notice(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::NOTICE, $message, $context); + } + + /** + * Interesting events. + * + * Example: User logs in, SQL logs. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function info(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::INFO, $message, $context); + } + + /** + * Detailed debug information. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function debug(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::DEBUG, $message, $context); + } + + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string|\Stringable $message + * @param array $context + * + * @return void + * + * @throws \Psr\Log\InvalidArgumentException + */ + abstract public function log($level, string|\Stringable $message, array $context = []): void; +} diff --git a/lib/psr/log/src/NullLogger.php b/lib/psr/log/src/NullLogger.php new file mode 100644 index 00000000000..c1cc3c0692a --- /dev/null +++ b/lib/psr/log/src/NullLogger.php @@ -0,0 +1,30 @@ +logger) { }` + * blocks. + */ +class NullLogger extends AbstractLogger +{ + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string|\Stringable $message + * @param array $context + * + * @return void + * + * @throws \Psr\Log\InvalidArgumentException + */ + public function log($level, string|\Stringable $message, array $context = []): void + { + // noop + } +} diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 51f25ad575d..c64830bdc6f 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -644,6 +644,22 @@ All rights reserved. MIT https://github.com/php-fig/http-message + + psr/http-server-handler + psr/http-server-handler + Common interface for HTTP server-side request handler + 1.0.2 + MIT + https://github.com/php-fig/http-server-handler + + + psr/http-server-middleware + psr/http-server-middleware + Common interface for HTTP server-side middleware + 1.0.2 + MIT + https://github.com/php-fig/http-server-middleware + psr/event-dispatcher event-dispatcher @@ -652,6 +668,14 @@ All rights reserved. MIT https://github.com/php-fig/event-dispatcher + + psr/log + log + Common interface for logging libraries + 3.0.0 + MIT + https://github.com/php-fig/log + phpxmlrpc phpxmlrpc