refactor: Cleanup git state - commit all staged changes
Major refactoring cleanup: - Add new controller architecture (class-controller-*.php) - Add new settings-v2 UI (views/settings-v2/) - Add new CSS architecture (agentic-sidebar.css, tokens) - Add esbuild build pipeline (scripts/build.js, package.json) - Add composer dependencies (vendor/) - Add frontend src directory (assets/js/src/index.jsx) - Add documentation files - Remove old/obsolete files (class-settings.php, old CSS) This commits all pending changes from previous refactoring efforts.
This commit is contained in:
109
vendor/symfony/contracts/CHANGELOG.md
vendored
Normal file
109
vendor/symfony/contracts/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
3.7
|
||||
---
|
||||
|
||||
* Add support for the `max_connect_duration` option in `HttpClientInterface`
|
||||
* Add support for hooked properties in `ServiceMethodsSubscriberTrait`
|
||||
* Add `ContainerAwareInterface`
|
||||
|
||||
3.6
|
||||
---
|
||||
|
||||
* Make `HttpClientTestCase` and `TranslatorTest` compatible with PHPUnit 10+
|
||||
* Add `NamespacedPoolInterface` to support namespace-based invalidation
|
||||
|
||||
3.5
|
||||
---
|
||||
|
||||
* Add `ServiceCollectionInterface`
|
||||
* Deprecate `ServiceSubscriberTrait`, use `ServiceMethodsSubscriberTrait` instead
|
||||
|
||||
3.4
|
||||
---
|
||||
|
||||
* Allow custom working directory in `TestHttpServer`
|
||||
|
||||
3.3
|
||||
---
|
||||
|
||||
* Add option `crypto_method` to `HttpClientInterface` to define the minimum TLS version to accept
|
||||
|
||||
3.2
|
||||
---
|
||||
|
||||
* Allow `ServiceSubscriberInterface::getSubscribedServices()` to return `SubscribedService[]`
|
||||
|
||||
3.0
|
||||
---
|
||||
|
||||
* Bump to PHP 8 minimum
|
||||
* Add native return types
|
||||
* Remove deprecated features
|
||||
|
||||
2.5
|
||||
---
|
||||
|
||||
* Add `SubscribedService` attribute, deprecate current `ServiceSubscriberTrait` usage
|
||||
|
||||
2.4
|
||||
---
|
||||
|
||||
* Add `HttpClientInterface::withOptions()`
|
||||
* Add `TranslatorInterface::getLocale()`
|
||||
|
||||
2.3.0
|
||||
-----
|
||||
|
||||
* added `Translation\TranslatableInterface` to enable value-objects to be translated
|
||||
* made `Translation\TranslatorTrait::getLocale()` fallback to intl's `Locale::getDefault()` when available
|
||||
|
||||
2.2.0
|
||||
-----
|
||||
|
||||
* added `Service\Attribute\Required` attribute for PHP 8
|
||||
|
||||
2.1.3
|
||||
-----
|
||||
|
||||
* fixed compat with PHP 8
|
||||
|
||||
2.1.0
|
||||
-----
|
||||
|
||||
* added "symfony/deprecation-contracts"
|
||||
|
||||
2.0.1
|
||||
-----
|
||||
|
||||
* added `/json` endpoints to the test mock HTTP server
|
||||
|
||||
2.0.0
|
||||
-----
|
||||
|
||||
* bumped minimum PHP version to 7.2 and added explicit type hints
|
||||
* made "psr/event-dispatcher" a required dependency of "symfony/event-dispatcher-contracts"
|
||||
* made "symfony/http-client-contracts" not experimental anymore
|
||||
|
||||
1.1.9
|
||||
-----
|
||||
|
||||
* fixed compat with PHP 8
|
||||
|
||||
1.1.0
|
||||
-----
|
||||
|
||||
* added `HttpClient` namespace with contracts for implementing flexible HTTP clients
|
||||
* added `EventDispatcherInterface` and `Event` in namespace `EventDispatcher`
|
||||
* added `ServiceProviderInterface` in namespace `Service`
|
||||
|
||||
1.0.0
|
||||
-----
|
||||
|
||||
* added `Service\ResetInterface` to provide a way to reset an object to its initial state
|
||||
* added `Translation\TranslatorInterface` and `Translation\TranslatorTrait`
|
||||
* added `Cache` contract to extend PSR-6 with tag invalidation, callback-based computation and stampede protection
|
||||
* added `Service\ServiceSubscriberInterface` to declare the dependencies of a class that consumes a service locator
|
||||
* added `Service\ServiceSubscriberTrait` to implement `Service\ServiceSubscriberInterface` using methods' return types
|
||||
* added `Service\ServiceLocatorTrait` to help implement PSR-11 service locators
|
||||
5
vendor/symfony/contracts/Cache/CHANGELOG.md
vendored
Normal file
5
vendor/symfony/contracts/Cache/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
The changelog is maintained for all Symfony contracts at the following URL:
|
||||
https://github.com/symfony/contracts/blob/main/CHANGELOG.md
|
||||
59
vendor/symfony/contracts/Cache/CacheInterface.php
vendored
Normal file
59
vendor/symfony/contracts/Cache/CacheInterface.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Cache;
|
||||
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Covers most simple to advanced caching needs.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface CacheInterface
|
||||
{
|
||||
/**
|
||||
* Fetches a value from the pool or computes it if not found.
|
||||
*
|
||||
* On cache misses, a callback is called that should return the missing value.
|
||||
* This callback is given a PSR-6 CacheItemInterface instance corresponding to the
|
||||
* requested key, that could be used e.g. for expiration control. It could also
|
||||
* be an ItemInterface instance when its additional features are needed.
|
||||
*
|
||||
* @template T
|
||||
*
|
||||
* @param string $key The key of the item to retrieve from the cache
|
||||
* @param (callable(CacheItemInterface,bool):T)|(callable(ItemInterface,bool):T)|CallbackInterface<T> $callback
|
||||
* @param float|null $beta A float that, as it grows, controls the likeliness of triggering
|
||||
* early expiration. 0 disables it, INF forces immediate expiration.
|
||||
* The default (or providing null) is implementation dependent but should
|
||||
* typically be 1.0, which should provide optimal stampede protection.
|
||||
* See https://en.wikipedia.org/wiki/Cache_stampede#Probabilistic_early_expiration
|
||||
* @param array &$metadata The metadata of the cached item {@see ItemInterface::getMetadata()}
|
||||
*
|
||||
* @return T
|
||||
*
|
||||
* @throws InvalidArgumentException When $key is not valid or when $beta is negative
|
||||
*/
|
||||
public function get(string $key, callable $callback, ?float $beta = null, ?array &$metadata = null): mixed;
|
||||
|
||||
/**
|
||||
* Removes an item from the pool.
|
||||
*
|
||||
* @param string $key The key to delete
|
||||
*
|
||||
* @return bool True if the item was successfully removed, false if there was any error
|
||||
*
|
||||
* @throws InvalidArgumentException When $key is not valid
|
||||
*/
|
||||
public function delete(string $key): bool;
|
||||
}
|
||||
75
vendor/symfony/contracts/Cache/CacheTrait.php
vendored
Normal file
75
vendor/symfony/contracts/Cache/CacheTrait.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Cache;
|
||||
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
// Help opcache.preload discover always-needed symbols
|
||||
class_exists(InvalidArgumentException::class);
|
||||
|
||||
/**
|
||||
* An implementation of CacheInterface for PSR-6 CacheItemPoolInterface classes.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
trait CacheTrait
|
||||
{
|
||||
public function get(string $key, callable $callback, ?float $beta = null, ?array &$metadata = null): mixed
|
||||
{
|
||||
return $this->doGet($this, $key, $callback, $beta, $metadata);
|
||||
}
|
||||
|
||||
public function delete(string $key): bool
|
||||
{
|
||||
return $this->deleteItem($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param-immediately-invoked-callable $callback
|
||||
*/
|
||||
private function doGet(CacheItemPoolInterface $pool, string $key, callable $callback, ?float $beta, ?array &$metadata = null, ?LoggerInterface $logger = null): mixed
|
||||
{
|
||||
if (0 > $beta ??= 1.0) {
|
||||
throw new class(\sprintf('Argument "$beta" provided to "%s::get()" must be a positive number, %f given.', static::class, $beta)) extends \InvalidArgumentException implements InvalidArgumentException {};
|
||||
}
|
||||
|
||||
$item = $pool->getItem($key);
|
||||
$recompute = !$item->isHit() || \INF === $beta;
|
||||
$metadata = $item instanceof ItemInterface ? $item->getMetadata() : [];
|
||||
|
||||
if (!$recompute && $metadata) {
|
||||
$expiry = $metadata[ItemInterface::METADATA_EXPIRY] ?? false;
|
||||
$ctime = $metadata[ItemInterface::METADATA_CTIME] ?? false;
|
||||
|
||||
if ($recompute = $ctime && $expiry && $expiry <= ($now = microtime(true)) - $ctime / 1000 * $beta * log(random_int(1, \PHP_INT_MAX) / \PHP_INT_MAX)) {
|
||||
// force applying defaultLifetime to expiry
|
||||
$item->expiresAt(null);
|
||||
$logger?->info('Item "{key}" elected for early recomputation {delta}s before its expiration', [
|
||||
'key' => $key,
|
||||
'delta' => \sprintf('%.1f', $expiry - $now),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($recompute) {
|
||||
$save = true;
|
||||
$item->set($callback($item, $save));
|
||||
if ($save) {
|
||||
$pool->save($item);
|
||||
}
|
||||
}
|
||||
|
||||
return $item->get();
|
||||
}
|
||||
}
|
||||
32
vendor/symfony/contracts/Cache/CallbackInterface.php
vendored
Normal file
32
vendor/symfony/contracts/Cache/CallbackInterface.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Cache;
|
||||
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
|
||||
/**
|
||||
* Computes and returns the cached value of an item.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @template T
|
||||
*/
|
||||
interface CallbackInterface
|
||||
{
|
||||
/**
|
||||
* @param CacheItemInterface|ItemInterface $item The item to compute the value for
|
||||
* @param bool &$save Should be set to false when the value should not be saved in the pool
|
||||
*
|
||||
* @return T The computed value for the passed item
|
||||
*/
|
||||
public function __invoke(CacheItemInterface $item, bool &$save): mixed;
|
||||
}
|
||||
65
vendor/symfony/contracts/Cache/ItemInterface.php
vendored
Normal file
65
vendor/symfony/contracts/Cache/ItemInterface.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Cache;
|
||||
|
||||
use Psr\Cache\CacheException;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Augments PSR-6's CacheItemInterface with support for tags and metadata.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface ItemInterface extends CacheItemInterface
|
||||
{
|
||||
/**
|
||||
* References the Unix timestamp stating when the item will expire.
|
||||
*/
|
||||
public const METADATA_EXPIRY = 'expiry';
|
||||
|
||||
/**
|
||||
* References the time the item took to be created, in milliseconds.
|
||||
*/
|
||||
public const METADATA_CTIME = 'ctime';
|
||||
|
||||
/**
|
||||
* References the list of tags that were assigned to the item, as string[].
|
||||
*/
|
||||
public const METADATA_TAGS = 'tags';
|
||||
|
||||
/**
|
||||
* Reserved characters that cannot be used in a key or tag.
|
||||
*/
|
||||
public const RESERVED_CHARACTERS = '{}()/\@:';
|
||||
|
||||
/**
|
||||
* Adds a tag to a cache item.
|
||||
*
|
||||
* Tags are strings that follow the same validation rules as keys.
|
||||
*
|
||||
* @param string|string[] $tags A tag or array of tags
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws InvalidArgumentException When $tag is not valid
|
||||
* @throws CacheException When the item comes from a pool that is not tag-aware
|
||||
*/
|
||||
public function tag(string|iterable $tags): static;
|
||||
|
||||
/**
|
||||
* Returns a list of metadata info that were saved alongside with the cached value.
|
||||
*
|
||||
* See ItemInterface::METADATA_* consts for keys potentially found in the returned array.
|
||||
*/
|
||||
public function getMetadata(): array;
|
||||
}
|
||||
19
vendor/symfony/contracts/Cache/LICENSE
vendored
Normal file
19
vendor/symfony/contracts/Cache/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2018-present Fabien Potencier
|
||||
|
||||
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.
|
||||
31
vendor/symfony/contracts/Cache/NamespacedPoolInterface.php
vendored
Normal file
31
vendor/symfony/contracts/Cache/NamespacedPoolInterface.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Cache;
|
||||
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Enables namespace-based invalidation by prefixing keys with backend-native namespace separators.
|
||||
*
|
||||
* Note that calling `withSubNamespace()` MUST NOT mutate the pool, but return a new instance instead.
|
||||
*
|
||||
* When tags are used, they MUST ignore sub-namespaces.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface NamespacedPoolInterface
|
||||
{
|
||||
/**
|
||||
* @throws InvalidArgumentException If the namespace contains characters found in ItemInterface's RESERVED_CHARACTERS
|
||||
*/
|
||||
public function withSubNamespace(string $namespace): static;
|
||||
}
|
||||
9
vendor/symfony/contracts/Cache/README.md
vendored
Normal file
9
vendor/symfony/contracts/Cache/README.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
Symfony Cache Contracts
|
||||
=======================
|
||||
|
||||
A set of abstractions extracted out of the Symfony components.
|
||||
|
||||
Can be used to build on semantics that the Symfony components proved useful and
|
||||
that already have battle tested implementations.
|
||||
|
||||
See https://github.com/symfony/contracts/blob/main/README.md for more information.
|
||||
38
vendor/symfony/contracts/Cache/TagAwareCacheInterface.php
vendored
Normal file
38
vendor/symfony/contracts/Cache/TagAwareCacheInterface.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Cache;
|
||||
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Allows invalidating cached items using tags.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface TagAwareCacheInterface extends CacheInterface
|
||||
{
|
||||
/**
|
||||
* Invalidates cached items using tags.
|
||||
*
|
||||
* When implemented on a PSR-6 pool, invalidation should not apply
|
||||
* to deferred items. Instead, they should be committed as usual.
|
||||
* This allows replacing old tagged values by new ones without
|
||||
* race conditions.
|
||||
*
|
||||
* @param string[] $tags An array of tags to invalidate
|
||||
*
|
||||
* @return bool True on success
|
||||
*
|
||||
* @throws InvalidArgumentException When $tags is not valid
|
||||
*/
|
||||
public function invalidateTags(array $tags): bool;
|
||||
}
|
||||
35
vendor/symfony/contracts/Cache/composer.json
vendored
Normal file
35
vendor/symfony/contracts/Cache/composer.json
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "symfony/cache-contracts",
|
||||
"type": "library",
|
||||
"description": "Generic abstractions related to caching",
|
||||
"keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"psr/cache": "^3.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Contracts\\Cache\\": "" }
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.7-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
}
|
||||
}
|
||||
5
vendor/symfony/contracts/Deprecation/CHANGELOG.md
vendored
Normal file
5
vendor/symfony/contracts/Deprecation/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
The changelog is maintained for all Symfony contracts at the following URL:
|
||||
https://github.com/symfony/contracts/blob/main/CHANGELOG.md
|
||||
19
vendor/symfony/contracts/Deprecation/LICENSE
vendored
Normal file
19
vendor/symfony/contracts/Deprecation/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2020-present Fabien Potencier
|
||||
|
||||
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.
|
||||
26
vendor/symfony/contracts/Deprecation/README.md
vendored
Normal file
26
vendor/symfony/contracts/Deprecation/README.md
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
Symfony Deprecation Contracts
|
||||
=============================
|
||||
|
||||
A generic function and convention to trigger deprecation notices.
|
||||
|
||||
This package provides a single global function named `trigger_deprecation()` that triggers silenced deprecation notices.
|
||||
|
||||
By using a custom PHP error handler such as the one provided by the Symfony ErrorHandler component,
|
||||
the triggered deprecations can be caught and logged for later discovery, both on dev and prod environments.
|
||||
|
||||
The function requires at least 3 arguments:
|
||||
- the name of the Composer package that is triggering the deprecation
|
||||
- the version of the package that introduced the deprecation
|
||||
- the message of the deprecation
|
||||
- more arguments can be provided: they will be inserted in the message using `printf()` formatting
|
||||
|
||||
Example:
|
||||
```php
|
||||
trigger_deprecation('symfony/blockchain', '8.9', 'Using "%s" is deprecated, use "%s" instead.', 'bitcoin', 'fabcoin');
|
||||
```
|
||||
|
||||
This will generate the following message:
|
||||
`Since symfony/blockchain 8.9: Using "bitcoin" is deprecated, use "fabcoin" instead.`
|
||||
|
||||
While not recommended, the deprecation notices can be completely ignored by declaring an empty
|
||||
`function trigger_deprecation() {}` in your application.
|
||||
35
vendor/symfony/contracts/Deprecation/composer.json
vendored
Normal file
35
vendor/symfony/contracts/Deprecation/composer.json
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "symfony/deprecation-contracts",
|
||||
"type": "library",
|
||||
"description": "A generic function and convention to trigger deprecation notices",
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"function.php"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.7-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
}
|
||||
}
|
||||
27
vendor/symfony/contracts/Deprecation/function.php
vendored
Normal file
27
vendor/symfony/contracts/Deprecation/function.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (!function_exists('trigger_deprecation')) {
|
||||
/**
|
||||
* Triggers a silenced deprecation notice.
|
||||
*
|
||||
* @param string $package The name of the Composer package that is triggering the deprecation
|
||||
* @param string $version The version of the package that introduced the deprecation
|
||||
* @param string $message The message of the deprecation
|
||||
* @param mixed ...$args Values to insert in the message using printf() formatting
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
function trigger_deprecation(string $package, string $version, string $message, mixed ...$args): void
|
||||
{
|
||||
@trigger_error(($package || $version ? "Since $package $version: " : '').($args ? vsprintf($message, $args) : $message), \E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
5
vendor/symfony/contracts/EventDispatcher/CHANGELOG.md
vendored
Normal file
5
vendor/symfony/contracts/EventDispatcher/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
The changelog is maintained for all Symfony contracts at the following URL:
|
||||
https://github.com/symfony/contracts/blob/main/CHANGELOG.md
|
||||
51
vendor/symfony/contracts/EventDispatcher/Event.php
vendored
Normal file
51
vendor/symfony/contracts/EventDispatcher/Event.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\EventDispatcher;
|
||||
|
||||
use Psr\EventDispatcher\StoppableEventInterface;
|
||||
|
||||
/**
|
||||
* Event is the base class for classes containing event data.
|
||||
*
|
||||
* This class contains no event data. It is used by events that do not pass
|
||||
* state information to an event handler when an event is raised.
|
||||
*
|
||||
* You can call the method stopPropagation() to abort the execution of
|
||||
* further listeners in your event listener.
|
||||
*
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class Event implements StoppableEventInterface
|
||||
{
|
||||
private bool $propagationStopped = false;
|
||||
|
||||
public function isPropagationStopped(): bool
|
||||
{
|
||||
return $this->propagationStopped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the propagation of the event to further event listeners.
|
||||
*
|
||||
* If multiple event listeners are connected to the same event, no
|
||||
* further event listener will be triggered once any trigger calls
|
||||
* stopPropagation().
|
||||
*/
|
||||
public function stopPropagation(): void
|
||||
{
|
||||
$this->propagationStopped = true;
|
||||
}
|
||||
}
|
||||
33
vendor/symfony/contracts/EventDispatcher/EventDispatcherInterface.php
vendored
Normal file
33
vendor/symfony/contracts/EventDispatcher/EventDispatcherInterface.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\EventDispatcher;
|
||||
|
||||
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* Allows providing hooks on domain-specific lifecycles by dispatching events.
|
||||
*/
|
||||
interface EventDispatcherInterface extends PsrEventDispatcherInterface
|
||||
{
|
||||
/**
|
||||
* Dispatches an event to all registered listeners.
|
||||
*
|
||||
* @template T of object
|
||||
*
|
||||
* @param T $event The event to pass to the event handlers/listeners
|
||||
* @param string|null $eventName The name of the event to dispatch. If not supplied,
|
||||
* the class of $event should be used instead.
|
||||
*
|
||||
* @return T The passed $event MUST be returned
|
||||
*/
|
||||
public function dispatch(object $event, ?string $eventName = null): object;
|
||||
}
|
||||
19
vendor/symfony/contracts/EventDispatcher/LICENSE
vendored
Normal file
19
vendor/symfony/contracts/EventDispatcher/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2018-present Fabien Potencier
|
||||
|
||||
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.
|
||||
9
vendor/symfony/contracts/EventDispatcher/README.md
vendored
Normal file
9
vendor/symfony/contracts/EventDispatcher/README.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
Symfony EventDispatcher Contracts
|
||||
=================================
|
||||
|
||||
A set of abstractions extracted out of the Symfony components.
|
||||
|
||||
Can be used to build on semantics that the Symfony components proved useful and
|
||||
that already have battle tested implementations.
|
||||
|
||||
See https://github.com/symfony/contracts/blob/main/README.md for more information.
|
||||
35
vendor/symfony/contracts/EventDispatcher/composer.json
vendored
Normal file
35
vendor/symfony/contracts/EventDispatcher/composer.json
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "symfony/event-dispatcher-contracts",
|
||||
"type": "library",
|
||||
"description": "Generic abstractions related to dispatching event",
|
||||
"keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"psr/event-dispatcher": "^1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Contracts\\EventDispatcher\\": "" }
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.7-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
}
|
||||
}
|
||||
5
vendor/symfony/contracts/HttpClient/CHANGELOG.md
vendored
Normal file
5
vendor/symfony/contracts/HttpClient/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
The changelog is maintained for all Symfony contracts at the following URL:
|
||||
https://github.com/symfony/contracts/blob/main/CHANGELOG.md
|
||||
71
vendor/symfony/contracts/HttpClient/ChunkInterface.php
vendored
Normal file
71
vendor/symfony/contracts/HttpClient/ChunkInterface.php
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient;
|
||||
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
/**
|
||||
* The interface of chunks returned by ResponseStreamInterface::current().
|
||||
*
|
||||
* When the chunk is first, last or timeout, the content MUST be empty.
|
||||
* When an unchecked timeout or a network error occurs, a TransportExceptionInterface
|
||||
* MUST be thrown by the destructor unless one was already thrown by another method.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface ChunkInterface
|
||||
{
|
||||
/**
|
||||
* Tells when the idle timeout has been reached.
|
||||
*
|
||||
* @throws TransportExceptionInterface on a network error
|
||||
*/
|
||||
public function isTimeout(): bool;
|
||||
|
||||
/**
|
||||
* Tells when headers just arrived.
|
||||
*
|
||||
* @throws TransportExceptionInterface on a network error or when the idle timeout is reached
|
||||
*/
|
||||
public function isFirst(): bool;
|
||||
|
||||
/**
|
||||
* Tells when the body just completed.
|
||||
*
|
||||
* @throws TransportExceptionInterface on a network error or when the idle timeout is reached
|
||||
*/
|
||||
public function isLast(): bool;
|
||||
|
||||
/**
|
||||
* Returns a [status code, headers] tuple when a 1xx status code was just received.
|
||||
*
|
||||
* @throws TransportExceptionInterface on a network error or when the idle timeout is reached
|
||||
*/
|
||||
public function getInformationalStatus(): ?array;
|
||||
|
||||
/**
|
||||
* Returns the content of the response chunk.
|
||||
*
|
||||
* @throws TransportExceptionInterface on a network error or when the idle timeout is reached
|
||||
*/
|
||||
public function getContent(): string;
|
||||
|
||||
/**
|
||||
* Returns the offset of the chunk in the response body.
|
||||
*/
|
||||
public function getOffset(): int;
|
||||
|
||||
/**
|
||||
* In case of error, returns the message that describes it.
|
||||
*/
|
||||
public function getError(): ?string;
|
||||
}
|
||||
21
vendor/symfony/contracts/HttpClient/Exception/ClientExceptionInterface.php
vendored
Normal file
21
vendor/symfony/contracts/HttpClient/Exception/ClientExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient\Exception;
|
||||
|
||||
/**
|
||||
* When a 4xx response is returned.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface ClientExceptionInterface extends HttpExceptionInterface
|
||||
{
|
||||
}
|
||||
21
vendor/symfony/contracts/HttpClient/Exception/DecodingExceptionInterface.php
vendored
Normal file
21
vendor/symfony/contracts/HttpClient/Exception/DecodingExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient\Exception;
|
||||
|
||||
/**
|
||||
* When a content-type cannot be decoded to the expected representation.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface DecodingExceptionInterface extends ExceptionInterface
|
||||
{
|
||||
}
|
||||
21
vendor/symfony/contracts/HttpClient/Exception/ExceptionInterface.php
vendored
Normal file
21
vendor/symfony/contracts/HttpClient/Exception/ExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient\Exception;
|
||||
|
||||
/**
|
||||
* The base interface for all exceptions in the contract.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface ExceptionInterface extends \Throwable
|
||||
{
|
||||
}
|
||||
24
vendor/symfony/contracts/HttpClient/Exception/HttpExceptionInterface.php
vendored
Normal file
24
vendor/symfony/contracts/HttpClient/Exception/HttpExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient\Exception;
|
||||
|
||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Base interface for HTTP-related exceptions.
|
||||
*
|
||||
* @author Anton Chernikov <anton_ch1989@mail.ru>
|
||||
*/
|
||||
interface HttpExceptionInterface extends ExceptionInterface
|
||||
{
|
||||
public function getResponse(): ResponseInterface;
|
||||
}
|
||||
21
vendor/symfony/contracts/HttpClient/Exception/RedirectionExceptionInterface.php
vendored
Normal file
21
vendor/symfony/contracts/HttpClient/Exception/RedirectionExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient\Exception;
|
||||
|
||||
/**
|
||||
* When a 3xx response is returned and the "max_redirects" option has been reached.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface RedirectionExceptionInterface extends HttpExceptionInterface
|
||||
{
|
||||
}
|
||||
21
vendor/symfony/contracts/HttpClient/Exception/ServerExceptionInterface.php
vendored
Normal file
21
vendor/symfony/contracts/HttpClient/Exception/ServerExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient\Exception;
|
||||
|
||||
/**
|
||||
* When a 5xx response is returned.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface ServerExceptionInterface extends HttpExceptionInterface
|
||||
{
|
||||
}
|
||||
21
vendor/symfony/contracts/HttpClient/Exception/TimeoutExceptionInterface.php
vendored
Normal file
21
vendor/symfony/contracts/HttpClient/Exception/TimeoutExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient\Exception;
|
||||
|
||||
/**
|
||||
* When an idle timeout occurs.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface TimeoutExceptionInterface extends TransportExceptionInterface
|
||||
{
|
||||
}
|
||||
21
vendor/symfony/contracts/HttpClient/Exception/TransportExceptionInterface.php
vendored
Normal file
21
vendor/symfony/contracts/HttpClient/Exception/TransportExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient\Exception;
|
||||
|
||||
/**
|
||||
* When any error happens at the transport level.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface TransportExceptionInterface extends ExceptionInterface
|
||||
{
|
||||
}
|
||||
126
vendor/symfony/contracts/HttpClient/HttpClientInterface.php
vendored
Normal file
126
vendor/symfony/contracts/HttpClient/HttpClientInterface.php
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient;
|
||||
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Test\HttpClientTestCase;
|
||||
|
||||
/**
|
||||
* Provides flexible methods for requesting HTTP resources synchronously or asynchronously.
|
||||
*
|
||||
* @see HttpClientTestCase for a reference test suite
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface HttpClientInterface
|
||||
{
|
||||
public const OPTIONS_DEFAULTS = [
|
||||
// array|string - an array containing the username as first value, and optionally the
|
||||
// password as the second one; or string like username:password - enabling HTTP Basic
|
||||
// authentication (RFC 7617)
|
||||
'auth_basic' => null,
|
||||
// string - a token enabling HTTP Bearer authorization (RFC 6750)
|
||||
'auth_bearer' => null,
|
||||
// string[] - associative array of query string values to merge with the request's URL
|
||||
'query' => [],
|
||||
// iterable|string[]|string[][] - headers names provided as keys or as part of values
|
||||
'headers' => [],
|
||||
// array|string|resource|\Traversable|\Closure - the callback SHOULD yield a string
|
||||
// smaller than the amount requested as argument; the empty string signals EOF; if
|
||||
// an array is passed, it is meant as a form payload of field names and values
|
||||
'body' => '',
|
||||
// mixed - if set, implementations MUST set the "body" option to the JSON-encoded
|
||||
// value and set the "content-type" header to a JSON-compatible value if it is not
|
||||
// explicitly defined in the headers option - typically "application/json"
|
||||
'json' => null,
|
||||
// mixed - any extra data to attach to the request (scalar, callable, object...) that
|
||||
// MUST be available via $response->getInfo('user_data') - not used internally
|
||||
'user_data' => null,
|
||||
// int - the maximum number of redirects to follow; a value lower than or equal to 0
|
||||
// means redirects should not be followed; "Authorization" and "Cookie" headers MUST
|
||||
// NOT follow except for the initial host name
|
||||
'max_redirects' => 20,
|
||||
// string - defaults to the best supported version, typically 1.1 or 2.0
|
||||
'http_version' => null,
|
||||
// string - the URI to resolve relative URLs, following rules in RFC 3986, section 2
|
||||
'base_uri' => null,
|
||||
// bool|resource|\Closure - whether the content of the response should be buffered or not,
|
||||
// or a stream resource where the response body should be written,
|
||||
// or a closure telling if/where the response should be buffered based on its headers
|
||||
'buffer' => true,
|
||||
// callable(int $dlNow, int $dlSize, array $info) - throwing any exceptions MUST abort the
|
||||
// request; it MUST be called on connection, on headers and on completion; it SHOULD be
|
||||
// called on upload/download of data and at least 1/s
|
||||
'on_progress' => null,
|
||||
// string[] - a map of host to IP address that SHOULD replace DNS resolution
|
||||
'resolve' => [],
|
||||
// string - by default, the proxy-related env vars handled by curl SHOULD be honored
|
||||
'proxy' => null,
|
||||
// string - a comma separated list of hosts that do not require a proxy to be reached
|
||||
'no_proxy' => null,
|
||||
// float - the idle timeout (in seconds) - defaults to ini_get('default_socket_timeout')
|
||||
'timeout' => null,
|
||||
// float - the maximum execution time (in seconds) for the request+response as a whole;
|
||||
// a value lower than or equal to 0 means it is unlimited
|
||||
'max_duration' => 0,
|
||||
// float - the maximum duration (in seconds) allowed for DNS + TCP + TLS connection;
|
||||
// a value lower than or equal to 0 means unlimited, as long as option timeout is respected
|
||||
'max_connect_duration' => 0,
|
||||
// string - the interface or the local socket to bind to
|
||||
'bindto' => '0',
|
||||
// see https://php.net/context.ssl for the following options
|
||||
'verify_peer' => true,
|
||||
'verify_host' => true,
|
||||
'cafile' => null,
|
||||
'capath' => null,
|
||||
'local_cert' => null,
|
||||
'local_pk' => null,
|
||||
'passphrase' => null,
|
||||
'ciphers' => null,
|
||||
'peer_fingerprint' => null,
|
||||
'capture_peer_cert_chain' => false,
|
||||
// STREAM_CRYPTO_METHOD_TLSv*_CLIENT - minimum TLS version
|
||||
'crypto_method' => \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
|
||||
// array - additional options that can be ignored if unsupported, unlike regular options
|
||||
'extra' => [
|
||||
// bool - whether to use persistent connections where supported
|
||||
'use_persistent_connections' => false,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Requests an HTTP resource.
|
||||
*
|
||||
* Responses MUST be lazy, but their status code MUST be
|
||||
* checked even if none of their public methods are called.
|
||||
*
|
||||
* Implementations are not required to support all options described above; they can also
|
||||
* support more custom options; but in any case, they MUST throw a TransportExceptionInterface
|
||||
* when an unsupported option is passed.
|
||||
*
|
||||
* @throws TransportExceptionInterface When an unsupported option is passed
|
||||
*/
|
||||
public function request(string $method, string $url, array $options = []): ResponseInterface;
|
||||
|
||||
/**
|
||||
* Yields responses chunk by chunk as they complete.
|
||||
*
|
||||
* @param ResponseInterface|iterable<array-key, ResponseInterface> $responses One or more responses created by the current HTTP client
|
||||
* @param float|null $timeout The idle timeout before yielding timeout chunks
|
||||
*/
|
||||
public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface;
|
||||
|
||||
/**
|
||||
* Returns a new instance of the client with new default options.
|
||||
*/
|
||||
public function withOptions(array $options): static;
|
||||
}
|
||||
19
vendor/symfony/contracts/HttpClient/LICENSE
vendored
Normal file
19
vendor/symfony/contracts/HttpClient/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2018-present Fabien Potencier
|
||||
|
||||
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.
|
||||
9
vendor/symfony/contracts/HttpClient/README.md
vendored
Normal file
9
vendor/symfony/contracts/HttpClient/README.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
Symfony HttpClient Contracts
|
||||
============================
|
||||
|
||||
A set of abstractions extracted out of the Symfony components.
|
||||
|
||||
Can be used to build on semantics that the Symfony components proved useful and
|
||||
that already have battle tested implementations.
|
||||
|
||||
See https://github.com/symfony/contracts/blob/main/README.md for more information.
|
||||
108
vendor/symfony/contracts/HttpClient/ResponseInterface.php
vendored
Normal file
108
vendor/symfony/contracts/HttpClient/ResponseInterface.php
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient;
|
||||
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
/**
|
||||
* A (lazily retrieved) HTTP response.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface ResponseInterface
|
||||
{
|
||||
/**
|
||||
* Gets the HTTP status code of the response.
|
||||
*
|
||||
* @throws TransportExceptionInterface when a network error occurs
|
||||
*/
|
||||
public function getStatusCode(): int;
|
||||
|
||||
/**
|
||||
* Gets the HTTP headers of the response.
|
||||
*
|
||||
* @param bool $throw Whether an exception should be thrown on 3/4/5xx status codes
|
||||
*
|
||||
* @return array<string, list<string>> The headers of the response keyed by header names in lowercase
|
||||
*
|
||||
* @throws TransportExceptionInterface When a network error occurs
|
||||
* @throws RedirectionExceptionInterface On a 3xx when $throw is true and the "max_redirects" option has been reached
|
||||
* @throws ClientExceptionInterface On a 4xx when $throw is true
|
||||
* @throws ServerExceptionInterface On a 5xx when $throw is true
|
||||
*/
|
||||
public function getHeaders(bool $throw = true): array;
|
||||
|
||||
/**
|
||||
* Gets the response body as a string.
|
||||
*
|
||||
* @param bool $throw Whether an exception should be thrown on 3/4/5xx status codes
|
||||
*
|
||||
* @throws TransportExceptionInterface When a network error occurs
|
||||
* @throws RedirectionExceptionInterface On a 3xx when $throw is true and the "max_redirects" option has been reached
|
||||
* @throws ClientExceptionInterface On a 4xx when $throw is true
|
||||
* @throws ServerExceptionInterface On a 5xx when $throw is true
|
||||
*/
|
||||
public function getContent(bool $throw = true): string;
|
||||
|
||||
/**
|
||||
* Gets the response body decoded as array, typically from a JSON payload.
|
||||
*
|
||||
* @param bool $throw Whether an exception should be thrown on 3/4/5xx status codes
|
||||
*
|
||||
* @throws DecodingExceptionInterface When the body cannot be decoded to an array
|
||||
* @throws TransportExceptionInterface When a network error occurs
|
||||
* @throws RedirectionExceptionInterface On a 3xx when $throw is true and the "max_redirects" option has been reached
|
||||
* @throws ClientExceptionInterface On a 4xx when $throw is true
|
||||
* @throws ServerExceptionInterface On a 5xx when $throw is true
|
||||
*/
|
||||
public function toArray(bool $throw = true): array;
|
||||
|
||||
/**
|
||||
* Closes the response stream and all related buffers.
|
||||
*
|
||||
* No further chunk will be yielded after this method has been called.
|
||||
*/
|
||||
public function cancel(): void;
|
||||
|
||||
/**
|
||||
* Returns info coming from the transport layer.
|
||||
*
|
||||
* This method SHOULD NOT throw any ExceptionInterface and SHOULD be non-blocking.
|
||||
* The returned info is "live": it can be empty and can change from one call to
|
||||
* another, as the request/response progresses.
|
||||
*
|
||||
* The following info MUST be returned:
|
||||
* - canceled (bool) - true if the response was canceled using ResponseInterface::cancel(), false otherwise
|
||||
* - error (string|null) - the error message when the transfer was aborted, null otherwise
|
||||
* - http_code (int) - the last response code or 0 when it is not known yet
|
||||
* - http_method (string) - the HTTP verb of the last request
|
||||
* - redirect_count (int) - the number of redirects followed while executing the request
|
||||
* - redirect_url (string|null) - the resolved location of redirect responses, null otherwise
|
||||
* - response_headers (array) - an array modelled after the special $http_response_header variable
|
||||
* - start_time (float) - the time when the request was sent or 0.0 when it's pending
|
||||
* - url (string) - the last effective URL of the request
|
||||
* - user_data (mixed) - the value of the "user_data" request option, null if not set
|
||||
*
|
||||
* When the "capture_peer_cert_chain" option is true, the "peer_certificate_chain"
|
||||
* attribute SHOULD list the peer certificates as an array of OpenSSL X.509 resources.
|
||||
*
|
||||
* Other info SHOULD be named after curl_getinfo()'s associative return value.
|
||||
*
|
||||
* @return mixed An array of all available info, or one of them when $type is
|
||||
* provided, or null when an unsupported type is requested
|
||||
*/
|
||||
public function getInfo(?string $type = null): mixed;
|
||||
}
|
||||
26
vendor/symfony/contracts/HttpClient/ResponseStreamInterface.php
vendored
Normal file
26
vendor/symfony/contracts/HttpClient/ResponseStreamInterface.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient;
|
||||
|
||||
/**
|
||||
* Yields response chunks, returned by HttpClientInterface::stream().
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @extends \Iterator<ResponseInterface, ChunkInterface>
|
||||
*/
|
||||
interface ResponseStreamInterface extends \Iterator
|
||||
{
|
||||
public function key(): ResponseInterface;
|
||||
|
||||
public function current(): ChunkInterface;
|
||||
}
|
||||
224
vendor/symfony/contracts/HttpClient/Test/Fixtures/web/index.php
vendored
Normal file
224
vendor/symfony/contracts/HttpClient/Test/Fixtures/web/index.php
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
if ('cli-server' !== \PHP_SAPI) {
|
||||
// safe guard against unwanted execution
|
||||
throw new \Exception("You cannot run this script directly, it's a fixture for TestHttpServer.");
|
||||
}
|
||||
|
||||
$vars = [];
|
||||
|
||||
if (!$_POST) {
|
||||
$_POST = json_decode(file_get_contents('php://input'), true);
|
||||
$_POST['content-type'] = $_SERVER['HTTP_CONTENT_TYPE'] ?? '?';
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'SERVER_PROTOCOL',
|
||||
'SERVER_NAME',
|
||||
'REQUEST_URI',
|
||||
'REQUEST_METHOD',
|
||||
'PHP_AUTH_USER',
|
||||
'PHP_AUTH_PW',
|
||||
'REMOTE_ADDR',
|
||||
'REMOTE_PORT',
|
||||
];
|
||||
|
||||
foreach ($headers as $k) {
|
||||
if (isset($_SERVER[$k])) {
|
||||
$vars[$k] = $_SERVER[$k];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($_SERVER as $k => $v) {
|
||||
if (str_starts_with($k, 'HTTP_')) {
|
||||
$vars[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$json = json_encode($vars, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
|
||||
|
||||
switch (parse_url($vars['REQUEST_URI'], \PHP_URL_PATH)) {
|
||||
default:
|
||||
exit;
|
||||
|
||||
case '/head':
|
||||
header('X-Request-Vars: '.json_encode($vars, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE));
|
||||
header('Content-Length: '.strlen($json), true);
|
||||
break;
|
||||
|
||||
case '/':
|
||||
case '/?a=a&b=b':
|
||||
case 'http://127.0.0.1:8057/':
|
||||
case 'http://localhost:8057/':
|
||||
ob_start('ob_gzhandler');
|
||||
break;
|
||||
|
||||
case '/103':
|
||||
header('HTTP/1.1 103 Early Hints');
|
||||
header('Link: </style.css>; rel=preload; as=style', false);
|
||||
header('Link: </script.js>; rel=preload; as=script', false);
|
||||
flush();
|
||||
usleep(1000);
|
||||
echo "HTTP/1.1 200 OK\r\n";
|
||||
echo "Date: Fri, 26 May 2017 10:02:11 GMT\r\n";
|
||||
echo "Content-Length: 13\r\n";
|
||||
echo "\r\n";
|
||||
echo 'Here the body';
|
||||
exit;
|
||||
|
||||
case '/404':
|
||||
header('Content-Type: application/json', true, 404);
|
||||
break;
|
||||
|
||||
case '/404-gzipped':
|
||||
header('Content-Type: text/plain', true, 404);
|
||||
ob_start('ob_gzhandler');
|
||||
@ob_flush();
|
||||
flush();
|
||||
usleep(300000);
|
||||
echo 'some text';
|
||||
exit;
|
||||
|
||||
case '/301':
|
||||
if ('Basic Zm9vOmJhcg==' === $vars['HTTP_AUTHORIZATION']) {
|
||||
header('Location: http://127.0.0.1:8057/302', true, 301);
|
||||
}
|
||||
break;
|
||||
|
||||
case '/301/bad-tld':
|
||||
header('Location: http://foo.example.', true, 301);
|
||||
break;
|
||||
|
||||
case '/301/invalid':
|
||||
header('Location: //?foo=bar', true, 301);
|
||||
break;
|
||||
|
||||
case '/301/proxy':
|
||||
case 'http://localhost:8057/301/proxy':
|
||||
case 'http://127.0.0.1:8057/301/proxy':
|
||||
header('Location: http://localhost:8057/', true, 301);
|
||||
break;
|
||||
|
||||
case '/302':
|
||||
if (!isset($vars['HTTP_AUTHORIZATION'])) {
|
||||
$location = $_GET['location'] ?? 'http://localhost:8057/';
|
||||
header('Location: '.$location, true, 302);
|
||||
}
|
||||
break;
|
||||
|
||||
case '/302/relative':
|
||||
header('Location: ..', true, 302);
|
||||
break;
|
||||
|
||||
case '/304':
|
||||
header('Content-Length: 10', true, 304);
|
||||
echo '12345';
|
||||
|
||||
return;
|
||||
|
||||
case '/304/etag':
|
||||
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
||||
header('ETag: "abc123"', true, 304);
|
||||
exit;
|
||||
}
|
||||
header('ETag: "abc123"');
|
||||
break;
|
||||
|
||||
case '/307':
|
||||
header('Location: http://localhost:8057/post', true, 307);
|
||||
break;
|
||||
|
||||
case '/length-broken':
|
||||
header('Content-Length: 1000');
|
||||
break;
|
||||
|
||||
case '/post':
|
||||
$output = json_encode($_POST + ['REQUEST_METHOD' => $vars['REQUEST_METHOD']], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
|
||||
header('Content-Type: application/json', true);
|
||||
header('Content-Length: '.strlen($output));
|
||||
echo $output;
|
||||
exit;
|
||||
|
||||
case '/timeout-header':
|
||||
usleep(300000);
|
||||
break;
|
||||
|
||||
case '/timeout-body':
|
||||
echo '<1>';
|
||||
@ob_flush();
|
||||
flush();
|
||||
usleep(500000);
|
||||
echo '<2>';
|
||||
exit;
|
||||
|
||||
case '/timeout-long':
|
||||
ignore_user_abort(false);
|
||||
sleep(1);
|
||||
while (true) {
|
||||
echo '<1>';
|
||||
@ob_flush();
|
||||
flush();
|
||||
usleep(500);
|
||||
}
|
||||
exit;
|
||||
|
||||
case '/chunked':
|
||||
header('Transfer-Encoding: chunked');
|
||||
echo "8\r\nSymfony \r\n5\r\nis aw\r\n6\r\nesome!\r\n0\r\n\r\n";
|
||||
exit;
|
||||
|
||||
case '/chunked-broken':
|
||||
header('Transfer-Encoding: chunked');
|
||||
echo "8\r\nSymfony \r\n5\r\nis aw\r\n6\r\ne";
|
||||
exit;
|
||||
|
||||
case '/gzip-broken':
|
||||
header('Content-Encoding: gzip');
|
||||
echo str_repeat('-', 1000);
|
||||
exit;
|
||||
|
||||
case '/max-duration':
|
||||
ignore_user_abort(false);
|
||||
while (true) {
|
||||
echo '<1>';
|
||||
@ob_flush();
|
||||
flush();
|
||||
usleep(500);
|
||||
}
|
||||
exit;
|
||||
|
||||
case '/json':
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
'documents' => [
|
||||
['id' => '/json/1'],
|
||||
['id' => '/json/2'],
|
||||
['id' => '/json/3'],
|
||||
],
|
||||
]);
|
||||
exit;
|
||||
|
||||
case '/json/1':
|
||||
case '/json/2':
|
||||
case '/json/3':
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
'title' => $vars['REQUEST_URI'],
|
||||
]);
|
||||
|
||||
exit;
|
||||
|
||||
case '/custom':
|
||||
if (isset($_GET['status'])) {
|
||||
http_response_code((int) $_GET['status']);
|
||||
}
|
||||
if (isset($_GET['headers']) && is_array($_GET['headers'])) {
|
||||
foreach ($_GET['headers'] as $header) {
|
||||
header($header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json', true);
|
||||
|
||||
echo $json;
|
||||
1230
vendor/symfony/contracts/HttpClient/Test/HttpClientTestCase.php
vendored
Normal file
1230
vendor/symfony/contracts/HttpClient/Test/HttpClientTestCase.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
62
vendor/symfony/contracts/HttpClient/Test/TestHttpServer.php
vendored
Normal file
62
vendor/symfony/contracts/HttpClient/Test/TestHttpServer.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\HttpClient\Test;
|
||||
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class TestHttpServer
|
||||
{
|
||||
private static array $process = [];
|
||||
|
||||
/**
|
||||
* @param string|null $workingDirectory
|
||||
*/
|
||||
public static function start(int $port = 8057/* , ?string $workingDirectory = null */): Process
|
||||
{
|
||||
$workingDirectory = \func_get_args()[1] ?? __DIR__.'/Fixtures/web';
|
||||
|
||||
if (0 > $port) {
|
||||
$port = -$port;
|
||||
$ip = '[::1]';
|
||||
} else {
|
||||
$ip = '127.0.0.1';
|
||||
}
|
||||
|
||||
if (isset(self::$process[$port])) {
|
||||
self::$process[$port]->stop();
|
||||
} else {
|
||||
register_shutdown_function(static function () use ($port) {
|
||||
self::$process[$port]->stop();
|
||||
});
|
||||
}
|
||||
|
||||
$finder = new PhpExecutableFinder();
|
||||
$process = new Process(array_merge([$finder->find(false) ?: throw new \Exception('PHP executable not found.')], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', $ip.':'.$port]));
|
||||
$process->setWorkingDirectory($workingDirectory);
|
||||
$process->start();
|
||||
self::$process[$port] = $process;
|
||||
|
||||
do {
|
||||
usleep(50000);
|
||||
} while (!@fopen('http://'.$ip.':'.$port, 'r'));
|
||||
|
||||
return $process;
|
||||
}
|
||||
|
||||
public static function stop(int $port = 8057)
|
||||
{
|
||||
if (isset(self::$process[$port])) {
|
||||
self::$process[$port]->stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
37
vendor/symfony/contracts/HttpClient/composer.json
vendored
Normal file
37
vendor/symfony/contracts/HttpClient/composer.json
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "symfony/http-client-contracts",
|
||||
"type": "library",
|
||||
"description": "Generic abstractions related to HTTP clients",
|
||||
"keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Contracts\\HttpClient\\": "" },
|
||||
"exclude-from-classmap": [
|
||||
"/Test/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.7-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
}
|
||||
}
|
||||
19
vendor/symfony/contracts/LICENSE
vendored
Normal file
19
vendor/symfony/contracts/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2018-present Fabien Potencier
|
||||
|
||||
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.
|
||||
54
vendor/symfony/contracts/README.md
vendored
Normal file
54
vendor/symfony/contracts/README.md
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
Symfony Contracts
|
||||
=================
|
||||
|
||||
A set of abstractions extracted out of the Symfony components.
|
||||
|
||||
Can be used to build on semantics that the Symfony components proved useful - and
|
||||
that already have battle tested implementations.
|
||||
|
||||
Design Principles
|
||||
-----------------
|
||||
|
||||
* contracts are split by domain, each into their own sub-namespaces;
|
||||
* contracts are small and consistent sets of PHP interfaces, traits, normative
|
||||
docblocks and reference test suites when applicable;
|
||||
* all contracts must have a proven implementation to enter this repository;
|
||||
* they must be backward compatible with existing Symfony components.
|
||||
|
||||
Packages that implement specific contracts should list them in the "provide"
|
||||
section of their "composer.json" file, using the `symfony/*-implementation`
|
||||
convention (e.g. `"provide": { "symfony/cache-implementation": "1.0" }`).
|
||||
|
||||
FAQ
|
||||
---
|
||||
|
||||
### How to use this package?
|
||||
|
||||
The abstractions in this package are useful to achieve loose coupling and
|
||||
interoperability. By using the provided interfaces as type hints, you are able
|
||||
to reuse any implementations that match their contracts. It could be a Symfony
|
||||
component, or another one provided by the PHP community at large.
|
||||
|
||||
Depending on their semantics, some interfaces can be combined with autowiring to
|
||||
seamlessly inject a service in your classes.
|
||||
|
||||
Others might be useful as labeling interfaces, to hint about a specific behavior
|
||||
that could be enabled when using autoconfiguration or manual service tagging (or
|
||||
any other means provided by your framework.)
|
||||
|
||||
### How is this different from PHP-FIG's PSRs?
|
||||
|
||||
When applicable, the provided contracts are built on top of PHP-FIG's PSRs. But
|
||||
the group has different goals and different processes. Here, we're focusing on
|
||||
providing abstractions that are useful on their own while still compatible with
|
||||
implementations provided by Symfony. Although not the main target, we hope that
|
||||
the declared contracts will directly or indirectly contribute to the PHP-FIG.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
* [Documentation](https://symfony.com/doc/current/components/contracts.html)
|
||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||
in the [main Symfony repository](https://github.com/symfony/symfony)
|
||||
25
vendor/symfony/contracts/Service/Attribute/Required.php
vendored
Normal file
25
vendor/symfony/contracts/Service/Attribute/Required.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service\Attribute;
|
||||
|
||||
/**
|
||||
* A required dependency.
|
||||
*
|
||||
* This attribute indicates that a property holds a required dependency. The annotated property or method should be
|
||||
* considered during the instantiation process of the containing class.
|
||||
*
|
||||
* @author Alexander M. Turek <me@derrabus.de>
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
|
||||
final class Required
|
||||
{
|
||||
}
|
||||
47
vendor/symfony/contracts/Service/Attribute/SubscribedService.php
vendored
Normal file
47
vendor/symfony/contracts/Service/Attribute/SubscribedService.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service\Attribute;
|
||||
|
||||
use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
|
||||
/**
|
||||
* For use as the return value for {@see ServiceSubscriberInterface}.
|
||||
*
|
||||
* @example new SubscribedService('http_client', HttpClientInterface::class, false, new Target('githubApi'))
|
||||
*
|
||||
* Use with {@see ServiceMethodsSubscriberTrait} to mark a method's return type
|
||||
* as a subscribed service.
|
||||
*
|
||||
* @author Kevin Bond <kevinbond@gmail.com>
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
|
||||
final class SubscribedService
|
||||
{
|
||||
/** @var object[] */
|
||||
public array $attributes;
|
||||
|
||||
/**
|
||||
* @param string|null $key The key to use for the service
|
||||
* @param string|null $type The service type (a class name, "string", "iterable", etc.)
|
||||
* @param bool $nullable Whether the service is optional
|
||||
* @param object|object[] $attributes One or more dependency injection attributes to use
|
||||
*/
|
||||
public function __construct(
|
||||
public ?string $key = null,
|
||||
public ?string $type = null,
|
||||
public bool $nullable = false,
|
||||
array|object $attributes = [],
|
||||
) {
|
||||
$this->attributes = \is_array($attributes) ? $attributes : [$attributes];
|
||||
}
|
||||
}
|
||||
5
vendor/symfony/contracts/Service/CHANGELOG.md
vendored
Normal file
5
vendor/symfony/contracts/Service/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
The changelog is maintained for all Symfony contracts at the following URL:
|
||||
https://github.com/symfony/contracts/blob/main/CHANGELOG.md
|
||||
22
vendor/symfony/contracts/Service/ContainerAwareInterface.php
vendored
Normal file
22
vendor/symfony/contracts/Service/ContainerAwareInterface.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Implemented by objects that expose a service container.
|
||||
*/
|
||||
interface ContainerAwareInterface
|
||||
{
|
||||
public function getContainer(): ContainerInterface;
|
||||
}
|
||||
19
vendor/symfony/contracts/Service/LICENSE
vendored
Normal file
19
vendor/symfony/contracts/Service/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2018-present Fabien Potencier
|
||||
|
||||
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.
|
||||
9
vendor/symfony/contracts/Service/README.md
vendored
Normal file
9
vendor/symfony/contracts/Service/README.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
Symfony Service Contracts
|
||||
=========================
|
||||
|
||||
A set of abstractions extracted out of the Symfony components.
|
||||
|
||||
Can be used to build on semantics that the Symfony components proved useful and
|
||||
that already have battle tested implementations.
|
||||
|
||||
See https://github.com/symfony/contracts/blob/main/README.md for more information.
|
||||
33
vendor/symfony/contracts/Service/ResetInterface.php
vendored
Normal file
33
vendor/symfony/contracts/Service/ResetInterface.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service;
|
||||
|
||||
/**
|
||||
* Provides a way to reset an object to its initial state.
|
||||
*
|
||||
* When calling the "reset()" method on an object, it should be put back to its
|
||||
* initial state. This usually means clearing any internal buffers and forwarding
|
||||
* the call to internal dependencies. All properties of the object should be put
|
||||
* back to the same state it had when it was first ready to use.
|
||||
*
|
||||
* This method could be called, for example, to recycle objects that are used as
|
||||
* services, so that they can be used to handle several requests in the same
|
||||
* process loop (note that we advise making your services stateless instead of
|
||||
* implementing this interface when possible.)
|
||||
*/
|
||||
interface ResetInterface
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function reset();
|
||||
}
|
||||
26
vendor/symfony/contracts/Service/ServiceCollectionInterface.php
vendored
Normal file
26
vendor/symfony/contracts/Service/ServiceCollectionInterface.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service;
|
||||
|
||||
/**
|
||||
* A ServiceProviderInterface that is also countable and iterable.
|
||||
*
|
||||
* @author Kevin Bond <kevinbond@gmail.com>
|
||||
*
|
||||
* @template-covariant T of mixed
|
||||
*
|
||||
* @extends ServiceProviderInterface<T>
|
||||
* @extends \IteratorAggregate<string, T>
|
||||
*/
|
||||
interface ServiceCollectionInterface extends ServiceProviderInterface, \Countable, \IteratorAggregate
|
||||
{
|
||||
}
|
||||
114
vendor/symfony/contracts/Service/ServiceLocatorTrait.php
vendored
Normal file
114
vendor/symfony/contracts/Service/ServiceLocatorTrait.php
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service;
|
||||
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
// Help opcache.preload discover always-needed symbols
|
||||
class_exists(ContainerExceptionInterface::class);
|
||||
class_exists(NotFoundExceptionInterface::class);
|
||||
|
||||
/**
|
||||
* A trait to help implement ServiceProviderInterface.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
trait ServiceLocatorTrait
|
||||
{
|
||||
private array $loading = [];
|
||||
private array $providedTypes;
|
||||
|
||||
/**
|
||||
* @param array<string, callable> $factories
|
||||
*/
|
||||
public function __construct(
|
||||
private array $factories,
|
||||
) {
|
||||
}
|
||||
|
||||
public function has(string $id): bool
|
||||
{
|
||||
return isset($this->factories[$id]);
|
||||
}
|
||||
|
||||
public function get(string $id): mixed
|
||||
{
|
||||
if (!isset($this->factories[$id])) {
|
||||
throw $this->createNotFoundException($id);
|
||||
}
|
||||
|
||||
if (isset($this->loading[$id])) {
|
||||
$ids = array_values($this->loading);
|
||||
$ids = \array_slice($this->loading, array_search($id, $ids));
|
||||
$ids[] = $id;
|
||||
|
||||
throw $this->createCircularReferenceException($id, $ids);
|
||||
}
|
||||
|
||||
$this->loading[$id] = $id;
|
||||
try {
|
||||
return $this->factories[$id]($this);
|
||||
} finally {
|
||||
unset($this->loading[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getProvidedServices(): array
|
||||
{
|
||||
if (!isset($this->providedTypes)) {
|
||||
$this->providedTypes = [];
|
||||
|
||||
foreach ($this->factories as $name => $factory) {
|
||||
if (!\is_callable($factory)) {
|
||||
$this->providedTypes[$name] = '?';
|
||||
} else {
|
||||
$type = (new \ReflectionFunction($factory))->getReturnType();
|
||||
|
||||
$this->providedTypes[$name] = $type ? ($type->allowsNull() ? '?' : '').($type instanceof \ReflectionNamedType ? $type->getName() : $type) : '?';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->providedTypes;
|
||||
}
|
||||
|
||||
private function createNotFoundException(string $id): NotFoundExceptionInterface
|
||||
{
|
||||
if (!$alternatives = array_keys($this->factories)) {
|
||||
$message = 'is empty...';
|
||||
} else {
|
||||
$last = array_pop($alternatives);
|
||||
if ($alternatives) {
|
||||
$message = \sprintf('only knows about the "%s" and "%s" services.', implode('", "', $alternatives), $last);
|
||||
} else {
|
||||
$message = \sprintf('only knows about the "%s" service.', $last);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->loading) {
|
||||
$message = \sprintf('The service "%s" has a dependency on a non-existent service "%s". This locator %s', end($this->loading), $id, $message);
|
||||
} else {
|
||||
$message = \sprintf('Service "%s" not found: the current service locator %s', $id, $message);
|
||||
}
|
||||
|
||||
return new class($message) extends \InvalidArgumentException implements NotFoundExceptionInterface {
|
||||
};
|
||||
}
|
||||
|
||||
private function createCircularReferenceException(string $id, array $path): ContainerExceptionInterface
|
||||
{
|
||||
return new class(\sprintf('Circular reference detected for service "%s", path: "%s".', $id, implode(' -> ', $path))) extends \RuntimeException implements ContainerExceptionInterface {
|
||||
};
|
||||
}
|
||||
}
|
||||
101
vendor/symfony/contracts/Service/ServiceMethodsSubscriberTrait.php
vendored
Normal file
101
vendor/symfony/contracts/Service/ServiceMethodsSubscriberTrait.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Contracts\Service\Attribute\Required;
|
||||
use Symfony\Contracts\Service\Attribute\SubscribedService;
|
||||
|
||||
/**
|
||||
* Implementation of ServiceSubscriberInterface that determines subscribed services
|
||||
* from methods that have the #[SubscribedService] attribute.
|
||||
*
|
||||
* Service ids are available as "ClassName::methodName" so that the implementation
|
||||
* of subscriber methods can be just `return $this->container->get(__METHOD__);`.
|
||||
*
|
||||
* @author Kevin Bond <kevinbond@gmail.com>
|
||||
*/
|
||||
trait ServiceMethodsSubscriberTrait
|
||||
{
|
||||
protected ContainerInterface $container;
|
||||
|
||||
public static function getSubscribedServices(): array
|
||||
{
|
||||
$services = method_exists(get_parent_class(self::class) ?: '', __FUNCTION__) ? parent::getSubscribedServices() : [];
|
||||
|
||||
$reflectors = [
|
||||
...(new \ReflectionClass(self::class))->getMethods(),
|
||||
...(new \ReflectionClass(self::class))->getProperties(),
|
||||
];
|
||||
|
||||
foreach ($reflectors as $reflector) {
|
||||
if (self::class !== $reflector->class) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$reflectionAttribute = $reflector->getAttributes(SubscribedService::class)[0] ?? null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($reflector instanceof \ReflectionMethod) {
|
||||
if ($reflector->isStatic() || $reflector->isAbstract() || $reflector->isGenerator() || $reflector->isInternal() || $reflector->getNumberOfRequiredParameters()) {
|
||||
throw new \LogicException(\sprintf('Cannot use "%s" on method "%s::%s()" (can only be used on non-static, non-abstract methods with no parameters).', SubscribedService::class, self::class, $reflector->name));
|
||||
}
|
||||
|
||||
if (!$autowireType = $reflector->getReturnType()) {
|
||||
throw new \LogicException(\sprintf('Cannot use "%s" on methods without a return type in "%s::%s()".', SubscribedService::class, $reflector->name, self::class));
|
||||
}
|
||||
|
||||
$defaultKey = self::class.'::'.$reflector->name;
|
||||
} elseif ($reflector instanceof \ReflectionProperty) {
|
||||
if (\PHP_VERSION_ID < 80400 || !$reflector->hasHook(\PropertyHookType::Get)) {
|
||||
throw new \LogicException(\sprintf('Cannot use "%s" on property "%s::$%s" (can only be used on properties with a get hook).', SubscribedService::class, self::class, $reflector->name));
|
||||
}
|
||||
|
||||
if (!$autowireType = $reflector->getType()) {
|
||||
throw new \LogicException(\sprintf('Cannot use "%s" on properties without a type in "%s::$%s".', SubscribedService::class, $reflector->name, self::class));
|
||||
}
|
||||
|
||||
$defaultKey = self::class.'::$'.$reflector->name.'::get';
|
||||
} else {
|
||||
throw new \LogicException('Unexpected reflector: '.get_debug_type($reflector));
|
||||
}
|
||||
|
||||
/* @var SubscribedService $attribute */
|
||||
$attribute = $reflectionAttribute->newInstance();
|
||||
$attribute->key ??= $defaultKey;
|
||||
$attribute->type ??= $autowireType instanceof \ReflectionNamedType ? $autowireType->getName() : (string) $autowireType;
|
||||
$attribute->nullable = $attribute->nullable ?: $autowireType->allowsNull();
|
||||
|
||||
if ($attribute->attributes) {
|
||||
$services[] = $attribute;
|
||||
} else {
|
||||
$services[$attribute->key] = ($attribute->nullable ? '?' : '').$attribute->type;
|
||||
}
|
||||
}
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
#[Required]
|
||||
public function setContainer(ContainerInterface $container): ?ContainerInterface
|
||||
{
|
||||
$ret = null;
|
||||
if (method_exists(get_parent_class(self::class) ?: '', __FUNCTION__)) {
|
||||
$ret = parent::setContainer($container);
|
||||
}
|
||||
|
||||
$this->container = $container;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
45
vendor/symfony/contracts/Service/ServiceProviderInterface.php
vendored
Normal file
45
vendor/symfony/contracts/Service/ServiceProviderInterface.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* A ServiceProviderInterface exposes the identifiers and the types of services provided by a container.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
* @author Mateusz Sip <mateusz.sip@gmail.com>
|
||||
*
|
||||
* @template-covariant T of mixed
|
||||
*/
|
||||
interface ServiceProviderInterface extends ContainerInterface
|
||||
{
|
||||
/**
|
||||
* @return T
|
||||
*/
|
||||
public function get(string $id): mixed;
|
||||
|
||||
public function has(string $id): bool;
|
||||
|
||||
/**
|
||||
* Returns an associative array of service types keyed by the identifiers provided by the current container.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* * ['logger' => 'Psr\Log\LoggerInterface'] means the object provides a service named "logger" that implements Psr\Log\LoggerInterface
|
||||
* * ['foo' => '?'] means the container provides service name "foo" of unspecified type
|
||||
* * ['bar' => '?Bar\Baz'] means the container provides a service "bar" of type Bar\Baz|null
|
||||
*
|
||||
* @return array<string, string> The provided service types, keyed by service names
|
||||
*/
|
||||
public function getProvidedServices(): array;
|
||||
}
|
||||
62
vendor/symfony/contracts/Service/ServiceSubscriberInterface.php
vendored
Normal file
62
vendor/symfony/contracts/Service/ServiceSubscriberInterface.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service;
|
||||
|
||||
use Symfony\Contracts\Service\Attribute\SubscribedService;
|
||||
|
||||
/**
|
||||
* A ServiceSubscriber exposes its dependencies via the static {@link getSubscribedServices} method.
|
||||
*
|
||||
* The getSubscribedServices method returns an array of service types required by such instances,
|
||||
* optionally keyed by the service names used internally. Service types that start with an interrogation
|
||||
* mark "?" are optional, while the other ones are mandatory service dependencies.
|
||||
*
|
||||
* The injected service locators SHOULD NOT allow access to any other services not specified by the method.
|
||||
*
|
||||
* It is expected that ServiceSubscriber instances consume PSR-11-based service locators internally.
|
||||
* This interface does not dictate any injection method for these service locators, although constructor
|
||||
* injection is recommended.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface ServiceSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Returns an array of service types (or {@see SubscribedService} objects) required
|
||||
* by such instances, optionally keyed by the service names used internally.
|
||||
*
|
||||
* For mandatory dependencies:
|
||||
*
|
||||
* * ['logger' => 'Psr\Log\LoggerInterface'] means the objects use the "logger" name
|
||||
* internally to fetch a service which must implement Psr\Log\LoggerInterface.
|
||||
* * ['loggers' => 'Psr\Log\LoggerInterface[]'] means the objects use the "loggers" name
|
||||
* internally to fetch an iterable of Psr\Log\LoggerInterface instances.
|
||||
* * ['Psr\Log\LoggerInterface'] is a shortcut for
|
||||
* * ['Psr\Log\LoggerInterface' => 'Psr\Log\LoggerInterface']
|
||||
*
|
||||
* otherwise:
|
||||
*
|
||||
* * ['logger' => '?Psr\Log\LoggerInterface'] denotes an optional dependency
|
||||
* * ['loggers' => '?Psr\Log\LoggerInterface[]'] denotes an optional iterable dependency
|
||||
* * ['?Psr\Log\LoggerInterface'] is a shortcut for
|
||||
* * ['Psr\Log\LoggerInterface' => '?Psr\Log\LoggerInterface']
|
||||
*
|
||||
* additionally, an array of {@see SubscribedService}'s can be returned:
|
||||
*
|
||||
* * [new SubscribedService('logger', Psr\Log\LoggerInterface::class)]
|
||||
* * [new SubscribedService(type: Psr\Log\LoggerInterface::class, nullable: true)]
|
||||
* * [new SubscribedService('http_client', HttpClientInterface::class, attributes: new Target('githubApi'))]
|
||||
*
|
||||
* @return string[]|SubscribedService[] The required service types, optionally keyed by service names
|
||||
*/
|
||||
public static function getSubscribedServices(): array;
|
||||
}
|
||||
84
vendor/symfony/contracts/Service/ServiceSubscriberTrait.php
vendored
Normal file
84
vendor/symfony/contracts/Service/ServiceSubscriberTrait.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Contracts\Service\Attribute\Required;
|
||||
use Symfony\Contracts\Service\Attribute\SubscribedService;
|
||||
|
||||
trigger_deprecation('symfony/contracts', 'v3.5', '"%s" is deprecated, use "ServiceMethodsSubscriberTrait" instead.', ServiceSubscriberTrait::class);
|
||||
|
||||
/**
|
||||
* Implementation of ServiceSubscriberInterface that determines subscribed services
|
||||
* from methods that have the #[SubscribedService] attribute.
|
||||
*
|
||||
* Service ids are available as "ClassName::methodName" so that the implementation
|
||||
* of subscriber methods can be just `return $this->container->get(__METHOD__);`.
|
||||
*
|
||||
* @property ContainerInterface $container
|
||||
*
|
||||
* @author Kevin Bond <kevinbond@gmail.com>
|
||||
*
|
||||
* @deprecated since symfony/contracts v3.5, use ServiceMethodsSubscriberTrait instead
|
||||
*/
|
||||
trait ServiceSubscriberTrait
|
||||
{
|
||||
public static function getSubscribedServices(): array
|
||||
{
|
||||
$services = method_exists(get_parent_class(self::class) ?: '', __FUNCTION__) ? parent::getSubscribedServices() : [];
|
||||
|
||||
foreach ((new \ReflectionClass(self::class))->getMethods() as $method) {
|
||||
if (self::class !== $method->class) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$attribute = $method->getAttributes(SubscribedService::class)[0] ?? null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) {
|
||||
throw new \LogicException(\sprintf('Cannot use "%s" on method "%s::%s()" (can only be used on non-static, non-abstract methods with no parameters).', SubscribedService::class, self::class, $method->name));
|
||||
}
|
||||
|
||||
if (!$returnType = $method->getReturnType()) {
|
||||
throw new \LogicException(\sprintf('Cannot use "%s" on methods without a return type in "%s::%s()".', SubscribedService::class, $method->name, self::class));
|
||||
}
|
||||
|
||||
/** @var SubscribedService $attribute */
|
||||
$attribute = $attribute->newInstance();
|
||||
$attribute->key ??= self::class.'::'.$method->name;
|
||||
$attribute->type ??= $returnType instanceof \ReflectionNamedType ? $returnType->getName() : (string) $returnType;
|
||||
$attribute->nullable = $attribute->nullable ?: $returnType->allowsNull();
|
||||
|
||||
if ($attribute->attributes) {
|
||||
$services[] = $attribute;
|
||||
} else {
|
||||
$services[$attribute->key] = ($attribute->nullable ? '?' : '').$attribute->type;
|
||||
}
|
||||
}
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
#[Required]
|
||||
public function setContainer(ContainerInterface $container): ?ContainerInterface
|
||||
{
|
||||
$ret = null;
|
||||
if (method_exists(get_parent_class(self::class) ?: '', __FUNCTION__)) {
|
||||
$ret = parent::setContainer($container);
|
||||
}
|
||||
|
||||
$this->container = $container;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
19
vendor/symfony/contracts/Service/Test/ServiceLocatorTest.php
vendored
Normal file
19
vendor/symfony/contracts/Service/Test/ServiceLocatorTest.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service\Test;
|
||||
|
||||
/**
|
||||
* @deprecated since PHPUnit 9.6
|
||||
*/
|
||||
class ServiceLocatorTest extends ServiceLocatorTestCase
|
||||
{
|
||||
}
|
||||
97
vendor/symfony/contracts/Service/Test/ServiceLocatorTestCase.php
vendored
Normal file
97
vendor/symfony/contracts/Service/Test/ServiceLocatorTestCase.php
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Service\Test;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Symfony\Contracts\Service\ServiceLocatorTrait;
|
||||
|
||||
abstract class ServiceLocatorTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param array<string, callable> $factories
|
||||
*/
|
||||
protected function getServiceLocator(array $factories): ContainerInterface
|
||||
{
|
||||
return new class($factories) implements ContainerInterface {
|
||||
use ServiceLocatorTrait;
|
||||
};
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$locator = $this->getServiceLocator([
|
||||
'foo' => static fn () => 'bar',
|
||||
'bar' => static fn () => 'baz',
|
||||
static fn () => 'dummy',
|
||||
]);
|
||||
|
||||
$this->assertTrue($locator->has('foo'));
|
||||
$this->assertTrue($locator->has('bar'));
|
||||
$this->assertFalse($locator->has('dummy'));
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$locator = $this->getServiceLocator([
|
||||
'foo' => static fn () => 'bar',
|
||||
'bar' => static fn () => 'baz',
|
||||
]);
|
||||
|
||||
$this->assertSame('bar', $locator->get('foo'));
|
||||
$this->assertSame('baz', $locator->get('bar'));
|
||||
}
|
||||
|
||||
public function testGetDoesNotMemoize()
|
||||
{
|
||||
$i = 0;
|
||||
$locator = $this->getServiceLocator([
|
||||
'foo' => static function () use (&$i) {
|
||||
++$i;
|
||||
|
||||
return 'bar';
|
||||
},
|
||||
]);
|
||||
|
||||
$this->assertSame('bar', $locator->get('foo'));
|
||||
$this->assertSame('bar', $locator->get('foo'));
|
||||
$this->assertSame(2, $i);
|
||||
}
|
||||
|
||||
public function testThrowsOnUndefinedInternalService()
|
||||
{
|
||||
$locator = $this->getServiceLocator([
|
||||
'foo' => static function () use (&$locator) { return $locator->get('bar'); },
|
||||
]);
|
||||
|
||||
$this->expectException(NotFoundExceptionInterface::class);
|
||||
$this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.');
|
||||
|
||||
$locator->get('foo');
|
||||
}
|
||||
|
||||
public function testThrowsOnCircularReference()
|
||||
{
|
||||
$locator = $this->getServiceLocator([
|
||||
'foo' => static function () use (&$locator) { return $locator->get('bar'); },
|
||||
'bar' => static function () use (&$locator) { return $locator->get('baz'); },
|
||||
'baz' => static function () use (&$locator) { return $locator->get('bar'); },
|
||||
]);
|
||||
|
||||
$this->expectException(ContainerExceptionInterface::class);
|
||||
$this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
|
||||
|
||||
$locator->get('foo');
|
||||
}
|
||||
}
|
||||
42
vendor/symfony/contracts/Service/composer.json
vendored
Normal file
42
vendor/symfony/contracts/Service/composer.json
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "symfony/service-contracts",
|
||||
"type": "library",
|
||||
"description": "Generic abstractions related to writing services",
|
||||
"keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"psr/container": "^1.1|^2.0",
|
||||
"symfony/deprecation-contracts": "^2.5|^3"
|
||||
},
|
||||
"conflict": {
|
||||
"ext-psr": "<1.1|>=2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Contracts\\Service\\": "" },
|
||||
"exclude-from-classmap": [
|
||||
"/Test/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.7-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
}
|
||||
}
|
||||
157
vendor/symfony/contracts/Tests/Cache/CacheTraitTest.php
vendored
Normal file
157
vendor/symfony/contracts/Tests/Cache/CacheTraitTest.php
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Tests\Cache;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Contracts\Cache\CacheTrait;
|
||||
|
||||
/**
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class CacheTraitTest extends TestCase
|
||||
{
|
||||
public function testSave()
|
||||
{
|
||||
$item = $this->createMock(CacheItemInterface::class);
|
||||
$item->method('set')
|
||||
->willReturn($item);
|
||||
$item->method('isHit')
|
||||
->willReturn(false);
|
||||
|
||||
$item->expects($this->once())
|
||||
->method('set')
|
||||
->with('computed data');
|
||||
|
||||
$cache = $this->getMockBuilder(TestPool::class)
|
||||
->onlyMethods(['getItem', 'save'])
|
||||
->getMock();
|
||||
$cache->expects($this->once())
|
||||
->method('getItem')
|
||||
->with('key')
|
||||
->willReturn($item);
|
||||
$cache->expects($this->once())
|
||||
->method('save');
|
||||
|
||||
$callback = static fn (CacheItemInterface $item) => 'computed data';
|
||||
|
||||
$cache->get('key', $callback);
|
||||
}
|
||||
|
||||
public function testNoCallbackCallOnHit()
|
||||
{
|
||||
$item = $this->createMock(CacheItemInterface::class);
|
||||
$item->method('isHit')
|
||||
->willReturn(true);
|
||||
|
||||
$item->expects($this->never())
|
||||
->method('set');
|
||||
|
||||
$cache = $this->getMockBuilder(TestPool::class)
|
||||
->onlyMethods(['getItem', 'save'])
|
||||
->getMock();
|
||||
|
||||
$cache->expects($this->once())
|
||||
->method('getItem')
|
||||
->with('key')
|
||||
->willReturn($item);
|
||||
$cache->expects($this->never())
|
||||
->method('save');
|
||||
|
||||
$callback = function (CacheItemInterface $item) {
|
||||
$this->fail('This code should never be reached');
|
||||
};
|
||||
|
||||
$cache->get('key', $callback);
|
||||
}
|
||||
|
||||
public function testRecomputeOnBetaInf()
|
||||
{
|
||||
$item = $this->createMock(CacheItemInterface::class);
|
||||
$item->method('set')
|
||||
->willReturn($item);
|
||||
$item->method('isHit')
|
||||
// We want to recompute even if it is a hit
|
||||
->willReturn(true);
|
||||
|
||||
$item->expects($this->once())
|
||||
->method('set')
|
||||
->with('computed data');
|
||||
|
||||
$cache = $this->getMockBuilder(TestPool::class)
|
||||
->onlyMethods(['getItem', 'save'])
|
||||
->getMock();
|
||||
|
||||
$cache->expects($this->once())
|
||||
->method('getItem')
|
||||
->with('key')
|
||||
->willReturn($item);
|
||||
$cache->expects($this->once())
|
||||
->method('save');
|
||||
|
||||
$callback = static fn (CacheItemInterface $item) => 'computed data';
|
||||
|
||||
$cache->get('key', $callback, \INF);
|
||||
}
|
||||
|
||||
public function testExceptionOnNegativeBeta()
|
||||
{
|
||||
$cache = new TestPool();
|
||||
|
||||
$callback = static fn (CacheItemInterface $item) => 'computed data';
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$cache->get('key', $callback, -2);
|
||||
}
|
||||
}
|
||||
|
||||
class TestPool implements CacheItemPoolInterface
|
||||
{
|
||||
use CacheTrait;
|
||||
|
||||
public function hasItem($key): bool
|
||||
{
|
||||
}
|
||||
|
||||
public function deleteItem($key): bool
|
||||
{
|
||||
}
|
||||
|
||||
public function deleteItems(array $keys = []): bool
|
||||
{
|
||||
}
|
||||
|
||||
public function getItem($key): CacheItemInterface
|
||||
{
|
||||
}
|
||||
|
||||
public function getItems(array $key = []): iterable
|
||||
{
|
||||
}
|
||||
|
||||
public function saveDeferred(CacheItemInterface $item): bool
|
||||
{
|
||||
}
|
||||
|
||||
public function save(CacheItemInterface $item): bool
|
||||
{
|
||||
}
|
||||
|
||||
public function commit(): bool
|
||||
{
|
||||
}
|
||||
|
||||
public function clear(): bool
|
||||
{
|
||||
}
|
||||
}
|
||||
50
vendor/symfony/contracts/Tests/Service/Fixtures/HookedPropertyService.php
vendored
Normal file
50
vendor/symfony/contracts/Tests/Service/Fixtures/HookedPropertyService.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Tests\Service\Fixtures;
|
||||
|
||||
use Symfony\Contracts\Service\Attribute\SubscribedService;
|
||||
use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
|
||||
final class HookedPropertyService implements ServiceSubscriberInterface
|
||||
{
|
||||
use ServiceMethodsSubscriberTrait;
|
||||
|
||||
#[SubscribedService]
|
||||
public MyDependency $myDependency {
|
||||
get => $this->container->get(__METHOD__);
|
||||
}
|
||||
|
||||
#[SubscribedService]
|
||||
public ?MyDependency $myNullableDependency {
|
||||
get => $this->container->has(__METHOD__) ? $this->container->get(__METHOD__) : null;
|
||||
}
|
||||
|
||||
#[SubscribedService(nullable: true)]
|
||||
public MyDependency $myTentativeDependency {
|
||||
get => $this->container->has(__METHOD__) ? $this->container->get(__METHOD__) : throw new \LogicException('Dependency not found');
|
||||
}
|
||||
|
||||
#[SubscribedService]
|
||||
public MyDependency $myCachedDependency {
|
||||
get => $this->myCachedDependency ??= $this->container->get(__METHOD__);
|
||||
}
|
||||
|
||||
#[SubscribedService(key: 'my_key')]
|
||||
public MyDependency $myKeyedDependency {
|
||||
get => $this->container->get('my_key');
|
||||
}
|
||||
}
|
||||
|
||||
final class MyDependency
|
||||
{
|
||||
}
|
||||
24
vendor/symfony/contracts/Tests/Service/Fixtures/NonHookedPropertyService.php
vendored
Normal file
24
vendor/symfony/contracts/Tests/Service/Fixtures/NonHookedPropertyService.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Tests\Service\Fixtures;
|
||||
|
||||
use Symfony\Contracts\Service\Attribute\SubscribedService;
|
||||
use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
|
||||
final class NonHookedPropertyService implements ServiceSubscriberInterface
|
||||
{
|
||||
use ServiceMethodsSubscriberTrait;
|
||||
|
||||
#[SubscribedService]
|
||||
public \stdClass $myDependency;
|
||||
}
|
||||
28
vendor/symfony/contracts/Tests/Service/Fixtures/WriteOnlyPropertyService.php
vendored
Normal file
28
vendor/symfony/contracts/Tests/Service/Fixtures/WriteOnlyPropertyService.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Tests\Service\Fixtures;
|
||||
|
||||
use Symfony\Contracts\Service\Attribute\SubscribedService;
|
||||
use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
|
||||
final class WriteOnlyPropertyService implements ServiceSubscriberInterface
|
||||
{
|
||||
use ServiceMethodsSubscriberTrait;
|
||||
|
||||
private mixed $myObject;
|
||||
|
||||
#[SubscribedService]
|
||||
public \stdClass $myDependency {
|
||||
set => $this->myObject = $value;
|
||||
}
|
||||
}
|
||||
105
vendor/symfony/contracts/Tests/Service/LegacyTestService.php
vendored
Normal file
105
vendor/symfony/contracts/Tests/Service/LegacyTestService.php
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Tests\Service;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Contracts\Service\Attribute\Required;
|
||||
use Symfony\Contracts\Service\Attribute\SubscribedService;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberTrait;
|
||||
|
||||
class LegacyParentTestService
|
||||
{
|
||||
public function aParentService(): Service1
|
||||
{
|
||||
}
|
||||
|
||||
public function setContainer(ContainerInterface $container): ?ContainerInterface
|
||||
{
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
|
||||
class LegacyTestService extends LegacyParentTestService implements ServiceSubscriberInterface
|
||||
{
|
||||
use ServiceSubscriberTrait;
|
||||
|
||||
protected $container;
|
||||
|
||||
#[SubscribedService]
|
||||
public function aService(): Service2
|
||||
{
|
||||
return $this->container->get(__METHOD__);
|
||||
}
|
||||
|
||||
#[SubscribedService(nullable: true)]
|
||||
public function nullableInAttribute(): Service2
|
||||
{
|
||||
if (!$this->container->has(__METHOD__)) {
|
||||
throw new \LogicException();
|
||||
}
|
||||
|
||||
return $this->container->get(__METHOD__);
|
||||
}
|
||||
|
||||
#[SubscribedService]
|
||||
public function nullableReturnType(): ?Service2
|
||||
{
|
||||
return $this->container->get(__METHOD__);
|
||||
}
|
||||
|
||||
#[SubscribedService(attributes: new Required())]
|
||||
public function withAttribute(): ?Service2
|
||||
{
|
||||
return $this->container->get(__METHOD__);
|
||||
}
|
||||
}
|
||||
|
||||
class LegacyChildTestService extends LegacyTestService
|
||||
{
|
||||
#[SubscribedService]
|
||||
public function aChildService(): LegacyService3
|
||||
{
|
||||
return $this->container->get(__METHOD__);
|
||||
}
|
||||
}
|
||||
|
||||
class LegacyParentWithMagicCall
|
||||
{
|
||||
public function __call($method, $args)
|
||||
{
|
||||
throw new \BadMethodCallException('Should not be called.');
|
||||
}
|
||||
|
||||
public static function __callStatic($method, $args)
|
||||
{
|
||||
throw new \BadMethodCallException('Should not be called.');
|
||||
}
|
||||
}
|
||||
|
||||
class LegacyService3
|
||||
{
|
||||
}
|
||||
|
||||
class LegacyParentTestService2
|
||||
{
|
||||
/** @var ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
public function setContainer(ContainerInterface $container)
|
||||
{
|
||||
$previous = $this->container ?? null;
|
||||
$this->container = $container;
|
||||
|
||||
return $previous;
|
||||
}
|
||||
}
|
||||
222
vendor/symfony/contracts/Tests/Service/ServiceMethodsSubscriberTraitTest.php
vendored
Normal file
222
vendor/symfony/contracts/Tests/Service/ServiceMethodsSubscriberTraitTest.php
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Tests\Service;
|
||||
|
||||
use PHPUnit\Framework\Attributes\RequiresPhp;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Contracts\Service\Attribute\Required;
|
||||
use Symfony\Contracts\Service\Attribute\SubscribedService;
|
||||
use Symfony\Contracts\Service\ServiceLocatorTrait;
|
||||
use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
use Symfony\Contracts\Tests\Service\Fixtures\HookedPropertyService;
|
||||
use Symfony\Contracts\Tests\Service\Fixtures\MyDependency;
|
||||
use Symfony\Contracts\Tests\Service\Fixtures\NonHookedPropertyService;
|
||||
use Symfony\Contracts\Tests\Service\Fixtures\WriteOnlyPropertyService;
|
||||
|
||||
class ServiceMethodsSubscriberTraitTest extends TestCase
|
||||
{
|
||||
public function testMethodsOnParentsAndChildrenAreIgnoredInGetSubscribedServices()
|
||||
{
|
||||
$expected = [
|
||||
TestService::class.'::aService' => Service2::class,
|
||||
TestService::class.'::nullableInAttribute' => '?'.Service2::class,
|
||||
TestService::class.'::nullableReturnType' => '?'.Service2::class,
|
||||
new SubscribedService(TestService::class.'::withAttribute', Service2::class, true, new Required()),
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, ChildTestService::getSubscribedServices());
|
||||
}
|
||||
|
||||
#[RequiresPhp('>= 8.4.0')]
|
||||
public function testHookedProperties()
|
||||
{
|
||||
$this->assertSame([
|
||||
HookedPropertyService::class.'::$myDependency::get' => MyDependency::class,
|
||||
HookedPropertyService::class.'::$myNullableDependency::get' => '?'.MyDependency::class,
|
||||
HookedPropertyService::class.'::$myTentativeDependency::get' => '?'.MyDependency::class,
|
||||
HookedPropertyService::class.'::$myCachedDependency::get' => MyDependency::class,
|
||||
'my_key' => MyDependency::class,
|
||||
], HookedPropertyService::getSubscribedServices());
|
||||
|
||||
$container = new class([HookedPropertyService::class.'::$myDependency::get' => static fn () => new MyDependency()]) implements ContainerInterface {
|
||||
use ServiceLocatorTrait;
|
||||
};
|
||||
|
||||
$service = new HookedPropertyService();
|
||||
$service->setContainer($container);
|
||||
|
||||
$this->assertInstanceOf(MyDependency::class, $service->myDependency);
|
||||
}
|
||||
|
||||
public function testPropertyHookRequired()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->expectExceptionMessage('Cannot use "Symfony\Contracts\Service\Attribute\SubscribedService" on property "Symfony\Contracts\Tests\Service\Fixtures\NonHookedPropertyService::$myDependency" (can only be used on properties with a get hook).');
|
||||
NonHookedPropertyService::getSubscribedServices();
|
||||
}
|
||||
|
||||
#[RequiresPhp('>= 8.4.0')]
|
||||
public function testPropertyWithGetHookRequired()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->expectExceptionMessage('Cannot use "Symfony\Contracts\Service\Attribute\SubscribedService" on property "Symfony\Contracts\Tests\Service\Fixtures\WriteOnlyPropertyService::$myDependency" (can only be used on properties with a get hook).');
|
||||
WriteOnlyPropertyService::getSubscribedServices();
|
||||
}
|
||||
|
||||
public function testSetContainerIsCalledOnParent()
|
||||
{
|
||||
$container = new class([]) implements ContainerInterface {
|
||||
use ServiceLocatorTrait;
|
||||
};
|
||||
|
||||
$this->assertSame($container, (new TestService())->setContainer($container));
|
||||
}
|
||||
|
||||
public function testParentNotCalledIfHasMagicCall()
|
||||
{
|
||||
$container = new class([]) implements ContainerInterface {
|
||||
use ServiceLocatorTrait;
|
||||
};
|
||||
$service = new class extends ParentWithMagicCall {
|
||||
use ServiceMethodsSubscriberTrait;
|
||||
};
|
||||
|
||||
$this->assertNull($service->setContainer($container));
|
||||
$this->assertSame([], $service::getSubscribedServices());
|
||||
}
|
||||
|
||||
public function testParentNotCalledIfNoParent()
|
||||
{
|
||||
$container = new class([]) implements ContainerInterface {
|
||||
use ServiceLocatorTrait;
|
||||
};
|
||||
$service = new class {
|
||||
use ServiceMethodsSubscriberTrait;
|
||||
};
|
||||
|
||||
$this->assertNull($service->setContainer($container));
|
||||
$this->assertSame([], $service::getSubscribedServices());
|
||||
}
|
||||
|
||||
public function testSetContainerCalledFirstOnParent()
|
||||
{
|
||||
$container1 = new class([]) implements ContainerInterface {
|
||||
use ServiceLocatorTrait;
|
||||
};
|
||||
$container2 = clone $container1;
|
||||
|
||||
$testService = new TestService2();
|
||||
$this->assertNull($testService->setContainer($container1));
|
||||
$this->assertSame($container1, $testService->setContainer($container2));
|
||||
}
|
||||
}
|
||||
|
||||
class ParentTestService
|
||||
{
|
||||
public function aParentService(): Service1
|
||||
{
|
||||
}
|
||||
|
||||
public function setContainer(ContainerInterface $container): ?ContainerInterface
|
||||
{
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
|
||||
class TestService extends ParentTestService implements ServiceSubscriberInterface
|
||||
{
|
||||
use ServiceMethodsSubscriberTrait;
|
||||
|
||||
protected ContainerInterface $container;
|
||||
|
||||
#[SubscribedService]
|
||||
public function aService(): Service2
|
||||
{
|
||||
return $this->container->get(__METHOD__);
|
||||
}
|
||||
|
||||
#[SubscribedService(nullable: true)]
|
||||
public function nullableInAttribute(): Service2
|
||||
{
|
||||
if (!$this->container->has(__METHOD__)) {
|
||||
throw new \LogicException();
|
||||
}
|
||||
|
||||
return $this->container->get(__METHOD__);
|
||||
}
|
||||
|
||||
#[SubscribedService]
|
||||
public function nullableReturnType(): ?Service2
|
||||
{
|
||||
return $this->container->get(__METHOD__);
|
||||
}
|
||||
|
||||
#[SubscribedService(attributes: new Required())]
|
||||
public function withAttribute(): ?Service2
|
||||
{
|
||||
return $this->container->get(__METHOD__);
|
||||
}
|
||||
}
|
||||
|
||||
class ChildTestService extends TestService
|
||||
{
|
||||
#[SubscribedService]
|
||||
public function aChildService(): Service3
|
||||
{
|
||||
return $this->container->get(__METHOD__);
|
||||
}
|
||||
}
|
||||
|
||||
class ParentWithMagicCall
|
||||
{
|
||||
public function __call($method, $args)
|
||||
{
|
||||
throw new \BadMethodCallException('Should not be called.');
|
||||
}
|
||||
|
||||
public static function __callStatic($method, $args)
|
||||
{
|
||||
throw new \BadMethodCallException('Should not be called.');
|
||||
}
|
||||
}
|
||||
|
||||
class Service1
|
||||
{
|
||||
}
|
||||
|
||||
class Service2
|
||||
{
|
||||
}
|
||||
|
||||
class Service3
|
||||
{
|
||||
}
|
||||
|
||||
class ParentTestService2
|
||||
{
|
||||
protected ContainerInterface $container;
|
||||
|
||||
public function setContainer(ContainerInterface $container)
|
||||
{
|
||||
$previous = $this->container ?? null;
|
||||
$this->container = $container;
|
||||
|
||||
return $previous;
|
||||
}
|
||||
}
|
||||
|
||||
class TestService2 extends ParentTestService2 implements ServiceSubscriberInterface
|
||||
{
|
||||
use ServiceMethodsSubscriberTrait;
|
||||
}
|
||||
97
vendor/symfony/contracts/Tests/Service/ServiceSubscriberTraitTest.php
vendored
Normal file
97
vendor/symfony/contracts/Tests/Service/ServiceSubscriberTraitTest.php
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Tests\Service;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Contracts\Service\Attribute\Required;
|
||||
use Symfony\Contracts\Service\Attribute\SubscribedService;
|
||||
use Symfony\Contracts\Service\ServiceLocatorTrait;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberTrait;
|
||||
|
||||
#[IgnoreDeprecations]
|
||||
#[Group('legacy')]
|
||||
class ServiceSubscriberTraitTest extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
class_exists(LegacyTestService::class);
|
||||
}
|
||||
|
||||
public function testMethodsOnParentsAndChildrenAreIgnoredInGetSubscribedServices()
|
||||
{
|
||||
$expected = [
|
||||
LegacyTestService::class.'::aService' => Service2::class,
|
||||
LegacyTestService::class.'::nullableInAttribute' => '?'.Service2::class,
|
||||
LegacyTestService::class.'::nullableReturnType' => '?'.Service2::class,
|
||||
new SubscribedService(LegacyTestService::class.'::withAttribute', Service2::class, true, new Required()),
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, LegacyChildTestService::getSubscribedServices());
|
||||
}
|
||||
|
||||
public function testSetContainerIsCalledOnParent()
|
||||
{
|
||||
$container = new class([]) implements ContainerInterface {
|
||||
use ServiceLocatorTrait;
|
||||
};
|
||||
|
||||
$this->assertSame($container, (new LegacyTestService())->setContainer($container));
|
||||
}
|
||||
|
||||
public function testParentNotCalledIfHasMagicCall()
|
||||
{
|
||||
$container = new class([]) implements ContainerInterface {
|
||||
use ServiceLocatorTrait;
|
||||
};
|
||||
$service = new class extends LegacyParentWithMagicCall {
|
||||
use ServiceSubscriberTrait;
|
||||
|
||||
private $container;
|
||||
};
|
||||
|
||||
$this->assertNull($service->setContainer($container));
|
||||
$this->assertSame([], $service::getSubscribedServices());
|
||||
}
|
||||
|
||||
public function testParentNotCalledIfNoParent()
|
||||
{
|
||||
$container = new class([]) implements ContainerInterface {
|
||||
use ServiceLocatorTrait;
|
||||
};
|
||||
$service = new class {
|
||||
use ServiceSubscriberTrait;
|
||||
|
||||
private $container;
|
||||
};
|
||||
|
||||
$this->assertNull($service->setContainer($container));
|
||||
$this->assertSame([], $service::getSubscribedServices());
|
||||
}
|
||||
|
||||
public function testSetContainerCalledFirstOnParent()
|
||||
{
|
||||
$container1 = new class([]) implements ContainerInterface {
|
||||
use ServiceLocatorTrait;
|
||||
};
|
||||
$container2 = clone $container1;
|
||||
|
||||
$testService = new class extends LegacyParentTestService2 implements ServiceSubscriberInterface {
|
||||
use ServiceSubscriberTrait;
|
||||
};
|
||||
$this->assertNull($testService->setContainer($container1));
|
||||
$this->assertSame($container1, $testService->setContainer($container2));
|
||||
}
|
||||
}
|
||||
5
vendor/symfony/contracts/Translation/CHANGELOG.md
vendored
Normal file
5
vendor/symfony/contracts/Translation/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
The changelog is maintained for all Symfony contracts at the following URL:
|
||||
https://github.com/symfony/contracts/blob/main/CHANGELOG.md
|
||||
19
vendor/symfony/contracts/Translation/LICENSE
vendored
Normal file
19
vendor/symfony/contracts/Translation/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2018-present Fabien Potencier
|
||||
|
||||
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.
|
||||
29
vendor/symfony/contracts/Translation/LocaleAwareInterface.php
vendored
Normal file
29
vendor/symfony/contracts/Translation/LocaleAwareInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Translation;
|
||||
|
||||
interface LocaleAwareInterface
|
||||
{
|
||||
/**
|
||||
* Sets the current locale.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException If the locale contains invalid characters
|
||||
*/
|
||||
public function setLocale(string $locale);
|
||||
|
||||
/**
|
||||
* Returns the current locale.
|
||||
*/
|
||||
public function getLocale(): string;
|
||||
}
|
||||
9
vendor/symfony/contracts/Translation/README.md
vendored
Normal file
9
vendor/symfony/contracts/Translation/README.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
Symfony Translation Contracts
|
||||
=============================
|
||||
|
||||
A set of abstractions extracted out of the Symfony components.
|
||||
|
||||
Can be used to build on semantics that the Symfony components proved useful and
|
||||
that already have battle tested implementations.
|
||||
|
||||
See https://github.com/symfony/contracts/blob/main/README.md for more information.
|
||||
401
vendor/symfony/contracts/Translation/Test/TranslatorTest.php
vendored
Normal file
401
vendor/symfony/contracts/Translation/Test/TranslatorTest.php
vendored
Normal file
@@ -0,0 +1,401 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Translation\Test;
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Translation\TranslatableMessage;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorTrait;
|
||||
|
||||
/**
|
||||
* Test should cover all languages mentioned on http://translate.sourceforge.net/wiki/l10n/pluralforms
|
||||
* and Plural forms mentioned on http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms.
|
||||
*
|
||||
* See also https://developer.mozilla.org/en/Localization_and_Plurals which mentions 15 rules having a maximum of 6 forms.
|
||||
* The mozilla code is also interesting to check for.
|
||||
*
|
||||
* As mentioned by chx http://drupal.org/node/1273968 we can cover all by testing number from 0 to 199
|
||||
*
|
||||
* The goal to cover all languages is too far fetched so this test case is smaller.
|
||||
*
|
||||
* @author Clemens Tolboom clemens@build2be.nl
|
||||
*/
|
||||
class TranslatorTest extends TestCase
|
||||
{
|
||||
private string $defaultLocale;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->defaultLocale = \Locale::getDefault();
|
||||
\Locale::setDefault('en');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
\Locale::setDefault($this->defaultLocale);
|
||||
}
|
||||
|
||||
public function getTranslator(): TranslatorInterface
|
||||
{
|
||||
return new class implements TranslatorInterface {
|
||||
use TranslatorTrait;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTransTests
|
||||
*/
|
||||
#[DataProvider('getTransTests')]
|
||||
public function testTrans($expected, $id, $parameters)
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$this->assertEquals($expected, $translator->trans($id, $parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTransChoiceTests
|
||||
*/
|
||||
#[DataProvider('getTransChoiceTests')]
|
||||
public function testTransChoiceWithExplicitLocale($expected, $id, $number)
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$this->assertEquals($expected, $translator->trans($id, ['%count%' => $number]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension intl
|
||||
*
|
||||
* @dataProvider getTransChoiceTests
|
||||
*/
|
||||
#[DataProvider('getTransChoiceTests')]
|
||||
#[RequiresPhpExtension('intl')]
|
||||
public function testTransChoiceWithDefaultLocale($expected, $id, $number)
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$this->assertEquals($expected, $translator->trans($id, ['%count%' => $number]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTransChoiceTests
|
||||
*/
|
||||
#[DataProvider('getTransChoiceTests')]
|
||||
public function testTransChoiceWithEnUsPosix($expected, $id, $number)
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
$translator->setLocale('en_US_POSIX');
|
||||
|
||||
$this->assertEquals($expected, $translator->trans($id, ['%count%' => $number]));
|
||||
}
|
||||
|
||||
public function testGetSetLocale()
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$this->assertEquals('en', $translator->getLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension intl
|
||||
*/
|
||||
#[RequiresPhpExtension('intl')]
|
||||
public function testGetLocaleReturnsDefaultLocaleIfNotSet()
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
\Locale::setDefault('pt_BR');
|
||||
$this->assertEquals('pt_BR', $translator->getLocale());
|
||||
|
||||
\Locale::setDefault('en');
|
||||
$this->assertEquals('en', $translator->getLocale());
|
||||
}
|
||||
|
||||
public static function getTransTests()
|
||||
{
|
||||
yield ['Symfony is great!', 'Symfony is great!', []];
|
||||
yield ['Symfony is awesome!', 'Symfony is %what%!', ['%what%' => 'awesome']];
|
||||
|
||||
if (class_exists(TranslatableMessage::class)) {
|
||||
yield ['He said "Symfony is awesome!".', 'He said "%what%".', ['%what%' => new TranslatableMessage('Symfony is %what%!', ['%what%' => 'awesome'])]];
|
||||
}
|
||||
}
|
||||
|
||||
public static function getTransChoiceTests()
|
||||
{
|
||||
return [
|
||||
['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
['There is one apple', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 1],
|
||||
['There are 10 apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10],
|
||||
['There are 0 apples', 'There is 1 apple|There are %count% apples', 0],
|
||||
['There is 1 apple', 'There is 1 apple|There are %count% apples', 1],
|
||||
['There are 10 apples', 'There is 1 apple|There are %count% apples', 10],
|
||||
// custom validation messages may be coded with a fixed value
|
||||
['There are 2 apples', 'There are 2 apples', 2],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInterval
|
||||
*/
|
||||
#[DataProvider('getInterval')]
|
||||
public function testInterval($expected, $number, $interval)
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$this->assertEquals($expected, $translator->trans($interval.' foo|[1,Inf[ bar', ['%count%' => $number]));
|
||||
}
|
||||
|
||||
public static function getInterval()
|
||||
{
|
||||
return [
|
||||
['foo', 3, '{1,2, 3 ,4}'],
|
||||
['bar', 10, '{1,2, 3 ,4}'],
|
||||
['bar', 3, '[1,2]'],
|
||||
['foo', 1, '[1,2]'],
|
||||
['foo', 2, '[1,2]'],
|
||||
['bar', 1, ']1,2['],
|
||||
['bar', 2, ']1,2['],
|
||||
['foo', log(0), '[-Inf,2['],
|
||||
['foo', -log(0), '[-2,+Inf]'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getChooseTests
|
||||
*/
|
||||
#[DataProvider('getChooseTests')]
|
||||
public function testChoose($expected, $id, $number, $locale = null)
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$this->assertEquals($expected, $translator->trans($id, ['%count%' => $number], null, $locale));
|
||||
}
|
||||
|
||||
public function testReturnMessageIfExactlyOneStandardRuleIsGiven()
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$this->assertEquals('There are two apples', $translator->trans('There are two apples', ['%count%' => 2]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getNonMatchingMessages
|
||||
*/
|
||||
#[DataProvider('getNonMatchingMessages')]
|
||||
public function testThrowExceptionIfMatchingMessageCannotBeFound($id, $number)
|
||||
{
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$translator->trans($id, ['%count%' => $number]);
|
||||
}
|
||||
|
||||
public static function getNonMatchingMessages()
|
||||
{
|
||||
return [
|
||||
['{0} There are no apples|{1} There is one apple', 2],
|
||||
['{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
['{1} There is one apple|]2,Inf] There are %count% apples', 2],
|
||||
['{0} There are no apples|There is one apple', 2],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getChooseTests()
|
||||
{
|
||||
return [
|
||||
['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
['There are no apples', '{0}There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
|
||||
['There is one apple', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 1],
|
||||
|
||||
['There are 10 apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10],
|
||||
['There are 10 apples', '{0} There are no apples|{1} There is one apple|]1,Inf]There are %count% apples', 10],
|
||||
['There are 10 apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10],
|
||||
|
||||
['There are 0 apples', 'There is one apple|There are %count% apples', 0],
|
||||
['There is one apple', 'There is one apple|There are %count% apples', 1],
|
||||
['There are 10 apples', 'There is one apple|There are %count% apples', 10],
|
||||
|
||||
['There are 0 apples', 'one: There is one apple|more: There are %count% apples', 0],
|
||||
['There is one apple', 'one: There is one apple|more: There are %count% apples', 1],
|
||||
['There are 10 apples', 'one: There is one apple|more: There are %count% apples', 10],
|
||||
|
||||
['There are no apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 0],
|
||||
['There is one apple', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 1],
|
||||
['There are 10 apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 10],
|
||||
|
||||
['', '{0}|{1} There is one apple|]1,Inf] There are %count% apples', 0],
|
||||
['', '{0} There are no apples|{1}|]1,Inf] There are %count% apples', 1],
|
||||
|
||||
// Indexed only tests which are Gettext PoFile* compatible strings.
|
||||
['There are 0 apples', 'There is one apple|There are %count% apples', 0],
|
||||
['There is one apple', 'There is one apple|There are %count% apples', 1],
|
||||
['There are 2 apples', 'There is one apple|There are %count% apples', 2],
|
||||
|
||||
// Tests for float numbers
|
||||
['There is almost one apple', '{0} There are no apples|]0,1[ There is almost one apple|{1} There is one apple|[1,Inf] There is more than one apple', 0.7],
|
||||
['There is one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1],
|
||||
['There is more than one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1.7],
|
||||
['There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0],
|
||||
['There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0.0],
|
||||
['There are no apples', '{0.0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0],
|
||||
|
||||
// Test texts with new-lines
|
||||
// with double-quotes and \n in id & double-quotes and actual newlines in text
|
||||
["This is a text with a\n new-line in it. Selector = 0.", '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 0],
|
||||
// with double-quotes and \n in id and single-quotes and actual newlines in text
|
||||
["This is a text with a\n new-line in it. Selector = 1.", '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 1],
|
||||
["This is a text with a\n new-line in it. Selector > 1.", '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 5],
|
||||
// with double-quotes and id split across lines
|
||||
['This is a text with a
|
||||
new-line in it. Selector = 1.', '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 1],
|
||||
// with single-quotes and id split across lines
|
||||
['This is a text with a
|
||||
new-line in it. Selector > 1.', '{0}This is a text with a
|
||||
new-line in it. Selector = 0.|{1}This is a text with a
|
||||
new-line in it. Selector = 1.|[1,Inf]This is a text with a
|
||||
new-line in it. Selector > 1.', 5],
|
||||
// with single-quotes and \n in text
|
||||
['This is a text with a\nnew-line in it. Selector = 0.', '{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.', 0],
|
||||
// with double-quotes and id split across lines
|
||||
["This is a text with a\nnew-line in it. Selector = 1.", "{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.", 1],
|
||||
// escape pipe
|
||||
['This is a text with | in it. Selector = 0.', '{0}This is a text with || in it. Selector = 0.|{1}This is a text with || in it. Selector = 1.', 0],
|
||||
// Empty plural set (2 plural forms) from a .PO file
|
||||
['', '|', 1],
|
||||
// Empty plural set (3 plural forms) from a .PO file
|
||||
['', '||', 1],
|
||||
|
||||
// Floating values
|
||||
['1.5 liters', '%count% liter|%count% liters', 1.5],
|
||||
['1.5 litre', '%count% litre|%count% litres', 1.5, 'fr'],
|
||||
|
||||
// Negative values
|
||||
['-1 degree', '%count% degree|%count% degrees', -1],
|
||||
['-1 degré', '%count% degré|%count% degrés', -1],
|
||||
['-1.5 degrees', '%count% degree|%count% degrees', -1.5],
|
||||
['-1.5 degré', '%count% degré|%count% degrés', -1.5, 'fr'],
|
||||
['-2 degrees', '%count% degree|%count% degrees', -2],
|
||||
['-2 degrés', '%count% degré|%count% degrés', -2],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider failingLangcodes
|
||||
*/
|
||||
#[DataProvider('failingLangcodes')]
|
||||
public function testFailedLangcodes($nplural, $langCodes)
|
||||
{
|
||||
$matrix = $this->generateTestData($langCodes);
|
||||
$this->validateMatrix($nplural, $matrix, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider successLangcodes
|
||||
*/
|
||||
#[DataProvider('successLangcodes')]
|
||||
public function testLangcodes($nplural, $langCodes)
|
||||
{
|
||||
$matrix = $this->generateTestData($langCodes);
|
||||
$this->validateMatrix($nplural, $matrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* This array should contain all currently known langcodes.
|
||||
*
|
||||
* As it is impossible to have this ever complete we should try as hard as possible to have it almost complete.
|
||||
*/
|
||||
public static function successLangcodes(): array
|
||||
{
|
||||
return [
|
||||
['1', ['ay', 'bo', 'cgg', 'dz', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky']],
|
||||
['2', ['nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM', 'en_US_POSIX']],
|
||||
['3', ['be', 'bs', 'cs', 'hr']],
|
||||
['4', ['cy', 'mt', 'sl']],
|
||||
['6', ['ar']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* This array should be at least empty within the near future.
|
||||
*
|
||||
* This both depends on a complete list trying to add above as understanding
|
||||
* the plural rules of the current failing languages.
|
||||
*
|
||||
* @return array With nplural together with langcodes
|
||||
*/
|
||||
public static function failingLangcodes(): array
|
||||
{
|
||||
return [
|
||||
['1', ['fa']],
|
||||
['2', ['jbo']],
|
||||
['3', ['cbs']],
|
||||
['4', ['gd', 'kw']],
|
||||
['5', ['ga']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* We validate only on the plural coverage. Thus the real rules is not tested.
|
||||
*
|
||||
* @param string $nplural Plural expected
|
||||
* @param array $matrix Containing langcodes and their plural index values
|
||||
*/
|
||||
protected function validateMatrix(string $nplural, array $matrix, bool $expectSuccess = true)
|
||||
{
|
||||
foreach ($matrix as $langCode => $data) {
|
||||
$indexes = array_flip($data);
|
||||
if ($expectSuccess) {
|
||||
$this->assertCount($nplural, $indexes, "Langcode '$langCode' has '$nplural' plural forms.");
|
||||
} else {
|
||||
$this->assertNotCount($nplural, $indexes, "Langcode '$langCode' has '$nplural' plural forms.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function generateTestData($langCodes)
|
||||
{
|
||||
$translator = new class {
|
||||
use TranslatorTrait {
|
||||
getPluralizationRule as public;
|
||||
}
|
||||
};
|
||||
|
||||
$matrix = [];
|
||||
foreach ($langCodes as $langCode) {
|
||||
for ($count = 0; $count < 200; ++$count) {
|
||||
$plural = $translator->getPluralizationRule($count, $langCode);
|
||||
$matrix[$langCode][$count] = $plural;
|
||||
}
|
||||
}
|
||||
|
||||
return $matrix;
|
||||
}
|
||||
}
|
||||
20
vendor/symfony/contracts/Translation/TranslatableInterface.php
vendored
Normal file
20
vendor/symfony/contracts/Translation/TranslatableInterface.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Translation;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface TranslatableInterface
|
||||
{
|
||||
public function trans(TranslatorInterface $translator, ?string $locale = null): string;
|
||||
}
|
||||
68
vendor/symfony/contracts/Translation/TranslatorInterface.php
vendored
Normal file
68
vendor/symfony/contracts/Translation/TranslatorInterface.php
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Translation;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface TranslatorInterface
|
||||
{
|
||||
/**
|
||||
* Translates the given message.
|
||||
*
|
||||
* When a number is provided as a parameter named "%count%", the message is parsed for plural
|
||||
* forms and a translation is chosen according to this number using the following rules:
|
||||
*
|
||||
* Given a message with different plural translations separated by a
|
||||
* pipe (|), this method returns the correct portion of the message based
|
||||
* on the given number, locale and the pluralization rules in the message
|
||||
* itself.
|
||||
*
|
||||
* The message supports two different types of pluralization rules:
|
||||
*
|
||||
* interval: {0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples
|
||||
* indexed: There is one apple|There are %count% apples
|
||||
*
|
||||
* The indexed solution can also contain labels (e.g. one: There is one apple).
|
||||
* This is purely for making the translations more clear - it does not
|
||||
* affect the functionality.
|
||||
*
|
||||
* The two methods can also be mixed:
|
||||
* {0} There are no apples|one: There is one apple|more: There are %count% apples
|
||||
*
|
||||
* An interval can represent a finite set of numbers:
|
||||
* {1,2,3,4}
|
||||
*
|
||||
* An interval can represent numbers between two numbers:
|
||||
* [1, +Inf]
|
||||
* ]-1,2[
|
||||
*
|
||||
* The left delimiter can be [ (inclusive) or ] (exclusive).
|
||||
* The right delimiter can be [ (exclusive) or ] (inclusive).
|
||||
* Beside numbers, you can use -Inf and +Inf for the infinite.
|
||||
*
|
||||
* @see https://en.wikipedia.org/wiki/ISO_31-11
|
||||
*
|
||||
* @param string $id The message id (may also be an object that can be cast to string)
|
||||
* @param array $parameters An array of parameters for the message
|
||||
* @param string|null $domain The domain for the message or null to use the default
|
||||
* @param string|null $locale The locale or null to use the default
|
||||
*
|
||||
* @throws \InvalidArgumentException If the locale contains invalid characters
|
||||
*/
|
||||
public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string;
|
||||
|
||||
/**
|
||||
* Returns the default locale.
|
||||
*/
|
||||
public function getLocale(): string;
|
||||
}
|
||||
231
vendor/symfony/contracts/Translation/TranslatorTrait.php
vendored
Normal file
231
vendor/symfony/contracts/Translation/TranslatorTrait.php
vendored
Normal file
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Contracts\Translation;
|
||||
|
||||
use Symfony\Component\Translation\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* A trait to help implement TranslatorInterface and LocaleAwareInterface.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
trait TranslatorTrait
|
||||
{
|
||||
private ?string $locale = null;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setLocale(string $locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
public function getLocale(): string
|
||||
{
|
||||
return $this->locale ?: (class_exists(\Locale::class) ? \Locale::getDefault() : 'en');
|
||||
}
|
||||
|
||||
public function trans(?string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string
|
||||
{
|
||||
if (null === $id || '' === $id) {
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach ($parameters as $k => $v) {
|
||||
if ($v instanceof TranslatableInterface) {
|
||||
$parameters[$k] = $v->trans($this, $locale);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($parameters['%count%']) || !is_numeric($parameters['%count%'])) {
|
||||
return strtr($id, $parameters);
|
||||
}
|
||||
|
||||
$number = (float) $parameters['%count%'];
|
||||
$locale = $locale ?: $this->getLocale();
|
||||
|
||||
$parts = [];
|
||||
if (preg_match('/^\|++$/', $id)) {
|
||||
$parts = explode('|', $id);
|
||||
} elseif (preg_match_all('/(?:\|\||[^\|])++/', $id, $matches)) {
|
||||
$parts = $matches[0];
|
||||
}
|
||||
|
||||
$intervalRegexp = <<<'EOF'
|
||||
/^(?P<interval>
|
||||
({\s*
|
||||
(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)
|
||||
\s*})
|
||||
|
||||
|
|
||||
|
||||
(?P<left_delimiter>[\[\]])
|
||||
\s*
|
||||
(?P<left>-Inf|\-?\d+(\.\d+)?)
|
||||
\s*,\s*
|
||||
(?P<right>\+?Inf|\-?\d+(\.\d+)?)
|
||||
\s*
|
||||
(?P<right_delimiter>[\[\]])
|
||||
)\s*(?P<message>.*?)$/xs
|
||||
EOF;
|
||||
|
||||
$standardRules = [];
|
||||
foreach ($parts as $part) {
|
||||
$part = trim(str_replace('||', '|', $part));
|
||||
|
||||
// try to match an explicit rule, then fallback to the standard ones
|
||||
if (preg_match($intervalRegexp, $part, $matches)) {
|
||||
if ($matches[2]) {
|
||||
foreach (explode(',', $matches[3]) as $n) {
|
||||
if ($number == $n) {
|
||||
return strtr($matches['message'], $parameters);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$leftNumber = '-Inf' === $matches['left'] ? -\INF : (float) $matches['left'];
|
||||
$rightNumber = is_numeric($matches['right']) ? (float) $matches['right'] : \INF;
|
||||
|
||||
if (('[' === $matches['left_delimiter'] ? $number >= $leftNumber : $number > $leftNumber)
|
||||
&& (']' === $matches['right_delimiter'] ? $number <= $rightNumber : $number < $rightNumber)
|
||||
) {
|
||||
return strtr($matches['message'], $parameters);
|
||||
}
|
||||
}
|
||||
} elseif (preg_match('/^\w+\:\s*(.*?)$/', $part, $matches)) {
|
||||
$standardRules[] = $matches[1];
|
||||
} else {
|
||||
$standardRules[] = $part;
|
||||
}
|
||||
}
|
||||
|
||||
$position = $this->getPluralizationRule($number, $locale);
|
||||
|
||||
if (!isset($standardRules[$position])) {
|
||||
// when there's exactly one rule given, and that rule is a standard
|
||||
// rule, use this rule
|
||||
if (1 === \count($parts) && isset($standardRules[0])) {
|
||||
return strtr($standardRules[0], $parameters);
|
||||
}
|
||||
|
||||
$message = \sprintf('Unable to choose a translation for "%s" with locale "%s" for value "%d". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %%count%% apples").', $id, $locale, $number);
|
||||
|
||||
if (class_exists(InvalidArgumentException::class)) {
|
||||
throw new InvalidArgumentException($message);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException($message);
|
||||
}
|
||||
|
||||
return strtr($standardRules[$position], $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plural position to use for the given locale and number.
|
||||
*
|
||||
* The plural rules are derived from code of the Zend Framework (2010-09-25),
|
||||
* which is subject to the new BSD license (http://framework.zend.com/license/new-bsd).
|
||||
* Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
*/
|
||||
private function getPluralizationRule(float $number, string $locale): int
|
||||
{
|
||||
$number = abs($number);
|
||||
|
||||
return match ('pt_BR' !== $locale && 'en_US_POSIX' !== $locale && \strlen($locale) > 3 ? substr($locale, 0, strrpos($locale, '_')) : $locale) {
|
||||
'af',
|
||||
'bn',
|
||||
'bg',
|
||||
'ca',
|
||||
'da',
|
||||
'de',
|
||||
'el',
|
||||
'en',
|
||||
'en_US_POSIX',
|
||||
'eo',
|
||||
'es',
|
||||
'et',
|
||||
'eu',
|
||||
'fa',
|
||||
'fi',
|
||||
'fo',
|
||||
'fur',
|
||||
'fy',
|
||||
'gl',
|
||||
'gu',
|
||||
'ha',
|
||||
'he',
|
||||
'hu',
|
||||
'is',
|
||||
'it',
|
||||
'ku',
|
||||
'lb',
|
||||
'ml',
|
||||
'mn',
|
||||
'mr',
|
||||
'nah',
|
||||
'nb',
|
||||
'ne',
|
||||
'nl',
|
||||
'nn',
|
||||
'no',
|
||||
'oc',
|
||||
'om',
|
||||
'or',
|
||||
'pa',
|
||||
'pap',
|
||||
'ps',
|
||||
'pt',
|
||||
'so',
|
||||
'sq',
|
||||
'sv',
|
||||
'sw',
|
||||
'ta',
|
||||
'te',
|
||||
'tk',
|
||||
'ur',
|
||||
'zu' => (1 == $number) ? 0 : 1,
|
||||
'am',
|
||||
'bh',
|
||||
'fil',
|
||||
'fr',
|
||||
'gun',
|
||||
'hi',
|
||||
'hy',
|
||||
'ln',
|
||||
'mg',
|
||||
'nso',
|
||||
'pt_BR',
|
||||
'ti',
|
||||
'wa' => ($number < 2) ? 0 : 1,
|
||||
'be',
|
||||
'bs',
|
||||
'hr',
|
||||
'ru',
|
||||
'sh',
|
||||
'sr',
|
||||
'uk' => ((1 == $number % 10) && (11 != $number % 100)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2),
|
||||
'cs',
|
||||
'sk' => (1 == $number) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2),
|
||||
'ga' => (1 == $number) ? 0 : ((2 == $number) ? 1 : 2),
|
||||
'lt' => ((1 == $number % 10) && (11 != $number % 100)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2),
|
||||
'sl' => (1 == $number % 100) ? 0 : ((2 == $number % 100) ? 1 : (((3 == $number % 100) || (4 == $number % 100)) ? 2 : 3)),
|
||||
'mk' => (1 == $number % 10) ? 0 : 1,
|
||||
'mt' => (1 == $number) ? 0 : (((0 == $number) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3)),
|
||||
'lv' => (0 == $number) ? 0 : (((1 == $number % 10) && (11 != $number % 100)) ? 1 : 2),
|
||||
'pl' => (1 == $number) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2),
|
||||
'cy' => (1 == $number) ? 0 : ((2 == $number) ? 1 : (((8 == $number) || (11 == $number)) ? 2 : 3)),
|
||||
'ro' => (1 == $number) ? 0 : (((0 == $number) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2),
|
||||
'ar' => (0 == $number) ? 0 : ((1 == $number) ? 1 : ((2 == $number) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5)))),
|
||||
default => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
37
vendor/symfony/contracts/Translation/composer.json
vendored
Normal file
37
vendor/symfony/contracts/Translation/composer.json
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "symfony/translation-contracts",
|
||||
"type": "library",
|
||||
"description": "Generic abstractions related to translation",
|
||||
"keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Contracts\\Translation\\": "" },
|
||||
"exclude-from-classmap": [
|
||||
"/Test/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.7-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
}
|
||||
}
|
||||
51
vendor/symfony/contracts/composer.json
vendored
Normal file
51
vendor/symfony/contracts/composer.json
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "symfony/contracts",
|
||||
"type": "library",
|
||||
"description": "A set of abstractions extracted out of the Symfony components",
|
||||
"keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards", "dev"],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"psr/cache": "^3.0",
|
||||
"psr/container": "^1.1|^2.0",
|
||||
"psr/event-dispatcher": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/polyfill-intl-idn": "^1.10"
|
||||
},
|
||||
"conflict": {
|
||||
"ext-psr": "<1.1|>=2"
|
||||
},
|
||||
"replace": {
|
||||
"symfony/cache-contracts": "self.version",
|
||||
"symfony/deprecation-contracts": "self.version",
|
||||
"symfony/event-dispatcher-contracts": "self.version",
|
||||
"symfony/http-client-contracts": "self.version",
|
||||
"symfony/service-contracts": "self.version",
|
||||
"symfony/translation-contracts": "self.version"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Contracts\\": "" },
|
||||
"files": [ "Deprecation/function.php" ],
|
||||
"exclude-from-classmap": [
|
||||
"**/Tests/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.7-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
44
vendor/symfony/contracts/phpunit.xml.dist
vendored
Normal file
44
vendor/symfony/contracts/phpunit.xml.dist
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/13.1/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
failOnDeprecation="true"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
>
|
||||
<php>
|
||||
<ini name="error_reporting" value="-1" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Symfony Contracts Test Suite">
|
||||
<directory>./Tests/</directory>
|
||||
<directory>./Service/Test/</directory>
|
||||
<directory>./Translation/Test/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<source ignoreSuppressionOfDeprecations="true">
|
||||
<deprecationTrigger ignoreUndefinedTriggers="true">
|
||||
<function>trigger_deprecation</function>
|
||||
<method>Doctrine\Deprecations\Deprecation::trigger</method>
|
||||
<method>Doctrine\Deprecations\Deprecation::triggerIfCalledFromOutside</method>
|
||||
</deprecationTrigger>
|
||||
<include>
|
||||
<directory>./</directory>
|
||||
</include>
|
||||
<exclude>
|
||||
<directory>./Tests</directory>
|
||||
<directory>./Service/Test/</directory>
|
||||
<directory>./Translation/Test/</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</source>
|
||||
|
||||
<extensions>
|
||||
<bootstrap class="Symfony\Bridge\PhpUnit\SymfonyExtension" />
|
||||
</extensions>
|
||||
</phpunit>
|
||||
13
vendor/symfony/contracts/splitsh.json
vendored
Normal file
13
vendor/symfony/contracts/splitsh.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"subtrees": {
|
||||
"cache-contracts": "Cache",
|
||||
"deprecation-contracts": "Deprecation",
|
||||
"event-dispatcher-contracts": "EventDispatcher",
|
||||
"http-client-contracts": "HttpClient",
|
||||
"service-contracts": "Service",
|
||||
"translation-contracts": "Translation"
|
||||
},
|
||||
"defaults": {
|
||||
"git_constraint": "<1.8.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user