conteneurisation de l'appli
This commit is contained in:
19
vendor/doctrine/annotations/LICENSE
vendored
Normal file
19
vendor/doctrine/annotations/LICENSE
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2006-2013 Doctrine Project
|
||||
|
||||
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.
|
24
vendor/doctrine/annotations/README.md
vendored
Normal file
24
vendor/doctrine/annotations/README.md
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
⚠️ PHP 8 introduced
|
||||
[attributes](https://www.php.net/manual/en/language.attributes.overview.php),
|
||||
which are a native replacement for annotations. As such, this library is
|
||||
considered feature complete, and should receive exclusively bugfixes and
|
||||
security fixes.
|
||||
|
||||
# Doctrine Annotations
|
||||
|
||||
[](https://github.com/doctrine/persistence/actions)
|
||||
[](https://www.versioneye.com/package/php--doctrine--annotations)
|
||||
[](https://www.versioneye.com/php/doctrine:annotations/references)
|
||||
[](https://packagist.org/packages/doctrine/annotations)
|
||||
[](https://packagist.org/packages/doctrine/annotations)
|
||||
|
||||
Docblock Annotations Parser library (extracted from [Doctrine Common](https://github.com/doctrine/common)).
|
||||
|
||||
## Documentation
|
||||
|
||||
See the [doctrine-project website](https://www.doctrine-project.org/projects/doctrine-annotations/en/latest/index.html).
|
||||
|
||||
## Contributing
|
||||
|
||||
When making a pull request, make sure your changes follow the
|
||||
[Coding Standard Guidelines](https://www.doctrine-project.org/projects/doctrine-coding-standard/en/current/reference/index.html#introduction).
|
72
vendor/doctrine/annotations/composer.json
vendored
Normal file
72
vendor/doctrine/annotations/composer.json
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"name": "doctrine/annotations",
|
||||
"description": "Docblock Annotations Parser",
|
||||
"license": "MIT",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"annotations",
|
||||
"docblock",
|
||||
"parser"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Guilherme Blanco",
|
||||
"email": "guilhermeblanco@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Roman Borschel",
|
||||
"email": "roman@code-factory.org"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin Eberlei",
|
||||
"email": "kontakt@beberlei.de"
|
||||
},
|
||||
{
|
||||
"name": "Jonathan Wage",
|
||||
"email": "jonwage@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"email": "schmittjoh@gmail.com"
|
||||
}
|
||||
],
|
||||
"homepage": "https://www.doctrine-project.org/projects/annotations.html",
|
||||
"require": {
|
||||
"php": "^7.1 || ^8.0",
|
||||
"ext-tokenizer": "*",
|
||||
"doctrine/lexer": "^1 || ^2",
|
||||
"psr/cache": "^1 || ^2 || ^3"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/cache": "^1.11 || ^2.0",
|
||||
"doctrine/coding-standard": "^9 || ^10",
|
||||
"phpstan/phpstan": "~1.4.10 || ^1.8.0",
|
||||
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
|
||||
"symfony/cache": "^4.4 || ^5.4 || ^6",
|
||||
"vimeo/psalm": "^4.10"
|
||||
},
|
||||
"suggest": {
|
||||
"php": "PHP 8.0 or higher comes with attributes, a native replacement for annotations"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Performance\\Common\\Annotations\\": "tests/Doctrine/Performance/Common/Annotations",
|
||||
"Doctrine\\Tests\\Common\\Annotations\\": "tests/Doctrine/Tests/Common/Annotations"
|
||||
},
|
||||
"files": [
|
||||
"tests/Doctrine/Tests/Common/Annotations/Fixtures/functions.php",
|
||||
"tests/Doctrine/Tests/Common/Annotations/Fixtures/SingleClassLOC1000.php"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||
},
|
||||
"sort-packages": true
|
||||
}
|
||||
}
|
252
vendor/doctrine/annotations/docs/en/annotations.rst
vendored
Normal file
252
vendor/doctrine/annotations/docs/en/annotations.rst
vendored
Normal file
@ -0,0 +1,252 @@
|
||||
Handling Annotations
|
||||
====================
|
||||
|
||||
There are several different approaches to handling annotations in PHP.
|
||||
Doctrine Annotations maps docblock annotations to PHP classes. Because
|
||||
not all docblock annotations are used for metadata purposes a filter is
|
||||
applied to ignore or skip classes that are not Doctrine annotations.
|
||||
|
||||
Take a look at the following code snippet:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace MyProject\Entities;
|
||||
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use Symfony\Component\Validator\Constraints AS Assert;
|
||||
|
||||
/**
|
||||
* @author Benjamin Eberlei
|
||||
* @ORM\Entity
|
||||
* @MyProject\Annotations\Foobarable
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* @ORM\Id @ORM\Column @ORM\GeneratedValue
|
||||
* @dummy
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
* @Assert\NotEmpty
|
||||
* @Assert\Email
|
||||
* @var string
|
||||
*/
|
||||
private $email;
|
||||
}
|
||||
|
||||
In this snippet you can see a variety of different docblock annotations:
|
||||
|
||||
- Documentation annotations such as ``@var`` and ``@author``. These
|
||||
annotations are ignored and never considered for throwing an
|
||||
exception due to wrongly used annotations.
|
||||
- Annotations imported through use statements. The statement ``use
|
||||
Doctrine\ORM\Mapping AS ORM`` makes all classes under that namespace
|
||||
available as ``@ORM\ClassName``. Same goes for the import of
|
||||
``@Assert``.
|
||||
- The ``@dummy`` annotation. It is not a documentation annotation and
|
||||
not ignored. For Doctrine Annotations it is not entirely clear how
|
||||
to handle this annotation. Depending on the configuration an exception
|
||||
(unknown annotation) will be thrown when parsing this annotation.
|
||||
- The fully qualified annotation ``@MyProject\Annotations\Foobarable``.
|
||||
This is transformed directly into the given class name.
|
||||
|
||||
How are these annotations loaded? From looking at the code you could
|
||||
guess that the ORM Mapping, Assert Validation and the fully qualified
|
||||
annotation can just be loaded using
|
||||
the defined PHP autoloaders. This is not the case however: For error
|
||||
handling reasons every check for class existence inside the
|
||||
``AnnotationReader`` sets the second parameter $autoload
|
||||
of ``class_exists($name, $autoload)`` to false. To work flawlessly the
|
||||
``AnnotationReader`` requires silent autoloaders which many autoloaders are
|
||||
not. Silent autoloading is NOT part of the `PSR-0 specification
|
||||
<https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md>`_
|
||||
for autoloading.
|
||||
|
||||
This is why Doctrine Annotations uses its own autoloading mechanism
|
||||
through a global registry. If you are wondering about the annotation
|
||||
registry being global, there is no other way to solve the architectural
|
||||
problems of autoloading annotation classes in a straightforward fashion.
|
||||
Additionally if you think about PHP autoloading then you recognize it is
|
||||
a global as well.
|
||||
|
||||
To anticipate the configuration section, making the above PHP class work
|
||||
with Doctrine Annotations requires this setup:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
|
||||
AnnotationRegistry::registerFile("/path/to/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
|
||||
AnnotationRegistry::registerAutoloadNamespace("Symfony\Component\Validator\Constraint", "/path/to/symfony/src");
|
||||
AnnotationRegistry::registerAutoloadNamespace("MyProject\Annotations", "/path/to/myproject/src");
|
||||
|
||||
$reader = new AnnotationReader();
|
||||
AnnotationReader::addGlobalIgnoredName('dummy');
|
||||
|
||||
The second block with the annotation registry calls registers all the
|
||||
three different annotation namespaces that are used.
|
||||
Doctrine Annotations saves all its annotations in a single file, that is
|
||||
why ``AnnotationRegistry#registerFile`` is used in contrast to
|
||||
``AnnotationRegistry#registerAutoloadNamespace`` which creates a PSR-0
|
||||
compatible loading mechanism for class to file names.
|
||||
|
||||
In the third block, we create the actual ``AnnotationReader`` instance.
|
||||
Note that we also add ``dummy`` to the global list of ignored
|
||||
annotations for which we do not throw exceptions. Setting this is
|
||||
necessary in our example case, otherwise ``@dummy`` would trigger an
|
||||
exception to be thrown during the parsing of the docblock of
|
||||
``MyProject\Entities\User#id``.
|
||||
|
||||
Setup and Configuration
|
||||
-----------------------
|
||||
|
||||
To use the annotations library is simple, you just need to create a new
|
||||
``AnnotationReader`` instance:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
|
||||
This creates a simple annotation reader with no caching other than in
|
||||
memory (in php arrays). Since parsing docblocks can be expensive you
|
||||
should cache this process by using a caching reader.
|
||||
|
||||
To cache annotations, you can create a ``Doctrine\Common\Annotations\PsrCachedReader``.
|
||||
This reader decorates the original reader and stores all annotations in a PSR-6
|
||||
cache:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Annotations\PsrCachedReader;
|
||||
|
||||
$cache = ... // instantiate a PSR-6 Cache pool
|
||||
|
||||
$reader = new PsrCachedReader(
|
||||
new AnnotationReader(),
|
||||
$cache,
|
||||
$debug = true
|
||||
);
|
||||
|
||||
The ``debug`` flag is used here as well to invalidate the cache files
|
||||
when the PHP class with annotations changed and should be used during
|
||||
development.
|
||||
|
||||
.. warning ::
|
||||
|
||||
The ``AnnotationReader`` works and caches under the
|
||||
assumption that all annotations of a doc-block are processed at
|
||||
once. That means that annotation classes that do not exist and
|
||||
aren't loaded and cannot be autoloaded (using the
|
||||
AnnotationRegistry) would never be visible and not accessible if a
|
||||
cache is used unless the cache is cleared and the annotations
|
||||
requested again, this time with all annotations defined.
|
||||
|
||||
By default the annotation reader returns a list of annotations with
|
||||
numeric indexes. If you want your annotations to be indexed by their
|
||||
class name you can wrap the reader in an ``IndexedReader``:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Annotations\IndexedReader;
|
||||
|
||||
$reader = new IndexedReader(new AnnotationReader());
|
||||
|
||||
.. warning::
|
||||
|
||||
You should never wrap the indexed reader inside a cached reader,
|
||||
only the other way around. This way you can re-use the cache with
|
||||
indexed or numeric keys, otherwise your code may experience failures
|
||||
due to caching in a numerical or indexed format.
|
||||
|
||||
Registering Annotations
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
As explained in the introduction, Doctrine Annotations uses its own
|
||||
autoloading mechanism to determine if a given annotation has a
|
||||
corresponding PHP class that can be autoloaded. For annotation
|
||||
autoloading you have to configure the
|
||||
``Doctrine\Common\Annotations\AnnotationRegistry``. There are three
|
||||
different mechanisms to configure annotation autoloading:
|
||||
|
||||
- Calling ``AnnotationRegistry#registerFile($file)`` to register a file
|
||||
that contains one or more annotation classes.
|
||||
- Calling ``AnnotationRegistry#registerNamespace($namespace, $dirs =
|
||||
null)`` to register that the given namespace contains annotations and
|
||||
that their base directory is located at the given $dirs or in the
|
||||
include path if ``NULL`` is passed. The given directories should *NOT*
|
||||
be the directory where classes of the namespace are in, but the base
|
||||
directory of the root namespace. The AnnotationRegistry uses a
|
||||
namespace to directory separator approach to resolve the correct path.
|
||||
- Calling ``AnnotationRegistry#registerLoader($callable)`` to register
|
||||
an autoloader callback. The callback accepts the class as first and
|
||||
only parameter and has to return ``true`` if the corresponding file
|
||||
was found and included.
|
||||
|
||||
.. note::
|
||||
|
||||
Loaders have to fail silently, if a class is not found even if it
|
||||
matches for example the namespace prefix of that loader. Never is a
|
||||
loader to throw a warning or exception if the loading failed
|
||||
otherwise parsing doc block annotations will become a huge pain.
|
||||
|
||||
A sample loader callback could look like:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
use Symfony\Component\ClassLoader\UniversalClassLoader;
|
||||
|
||||
AnnotationRegistry::registerLoader(function($class) {
|
||||
$file = str_replace("\\", DIRECTORY_SEPARATOR, $class) . ".php";
|
||||
|
||||
if (file_exists("/my/base/path/" . $file)) {
|
||||
// file_exists() makes sure that the loader fails silently
|
||||
require "/my/base/path/" . $file;
|
||||
}
|
||||
});
|
||||
|
||||
$loader = new UniversalClassLoader();
|
||||
AnnotationRegistry::registerLoader(array($loader, "loadClass"));
|
||||
|
||||
|
||||
Ignoring missing exceptions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
By default an exception is thrown from the ``AnnotationReader`` if an
|
||||
annotation was found that:
|
||||
|
||||
- is not part of the list of ignored "documentation annotations";
|
||||
- was not imported through a use statement;
|
||||
- is not a fully qualified class that exists.
|
||||
|
||||
You can disable this behavior for specific names if your docblocks do
|
||||
not follow strict requirements:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
AnnotationReader::addGlobalIgnoredName('foo');
|
||||
|
||||
PHP Imports
|
||||
~~~~~~~~~~~
|
||||
|
||||
By default the annotation reader parses the use-statement of a php file
|
||||
to gain access to the import rules and register them for the annotation
|
||||
processing. Only if you are using PHP Imports can you validate the
|
||||
correct usage of annotations and throw exceptions if you misspelled an
|
||||
annotation. This mechanism is enabled by default.
|
||||
|
||||
To ease the upgrade path, we still allow you to disable this mechanism.
|
||||
Note however that we will remove this in future versions:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
$reader->setEnabledPhpImports(false);
|
443
vendor/doctrine/annotations/docs/en/custom.rst
vendored
Normal file
443
vendor/doctrine/annotations/docs/en/custom.rst
vendored
Normal file
@ -0,0 +1,443 @@
|
||||
Custom Annotation Classes
|
||||
=========================
|
||||
|
||||
If you want to define your own annotations, you just have to group them
|
||||
in a namespace and register this namespace in the ``AnnotationRegistry``.
|
||||
Annotation classes have to contain a class-level docblock with the text
|
||||
``@Annotation``:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace MyCompany\Annotations;
|
||||
|
||||
/** @Annotation */
|
||||
class Bar
|
||||
{
|
||||
// some code
|
||||
}
|
||||
|
||||
Inject annotation values
|
||||
------------------------
|
||||
|
||||
The annotation parser checks if the annotation constructor has arguments,
|
||||
if so then it will pass the value array, otherwise it will try to inject
|
||||
values into public properties directly:
|
||||
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace MyCompany\Annotations;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*
|
||||
* Some Annotation using a constructor
|
||||
*/
|
||||
class Bar
|
||||
{
|
||||
private $foo;
|
||||
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->foo = $values['foo'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*
|
||||
* Some Annotation without a constructor
|
||||
*/
|
||||
class Foo
|
||||
{
|
||||
public $bar;
|
||||
}
|
||||
|
||||
Optional: Constructors with Named Parameters
|
||||
--------------------------------------------
|
||||
|
||||
Starting with Annotations v1.11 a new annotation instantiation strategy
|
||||
is available that aims at compatibility of Annotation classes with the PHP 8
|
||||
attribute feature. You need to declare a constructor with regular parameter
|
||||
names that match the named arguments in the annotation syntax.
|
||||
|
||||
To enable this feature, you can tag your annotation class with
|
||||
``@NamedArgumentConstructor`` (available from v1.12) or implement the
|
||||
``Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation`` interface
|
||||
(available from v1.11 and deprecated as of v1.12).
|
||||
When using the ``@NamedArgumentConstructor`` tag, the first argument of the
|
||||
constructor is considered as the default one.
|
||||
|
||||
|
||||
Usage with the ``@NamedArgumentConstructor`` tag
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace MyCompany\Annotations;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @NamedArgumentConstructor
|
||||
*/
|
||||
class Bar implements NamedArgumentConstructorAnnotation
|
||||
{
|
||||
private $foo;
|
||||
|
||||
public function __construct(string $foo)
|
||||
{
|
||||
$this->foo = $foo;
|
||||
}
|
||||
}
|
||||
|
||||
/** Usable with @Bar(foo="baz") */
|
||||
/** Usable with @Bar("baz") */
|
||||
|
||||
In combination with PHP 8's constructor property promotion feature
|
||||
you can simplify this to:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace MyCompany\Annotations;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @NamedArgumentConstructor
|
||||
*/
|
||||
class Bar implements NamedArgumentConstructorAnnotation
|
||||
{
|
||||
public function __construct(private string $foo) {}
|
||||
}
|
||||
|
||||
|
||||
Usage with the
|
||||
``Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation``
|
||||
interface (v1.11, deprecated as of v1.12):
|
||||
.. code-block:: php
|
||||
|
||||
namespace MyCompany\Annotations;
|
||||
|
||||
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
|
||||
|
||||
/** @Annotation */
|
||||
class Bar implements NamedArgumentConstructorAnnotation
|
||||
{
|
||||
private $foo;
|
||||
|
||||
public function __construct(private string $foo) {}
|
||||
}
|
||||
|
||||
/** Usable with @Bar(foo="baz") */
|
||||
|
||||
Annotation Target
|
||||
-----------------
|
||||
|
||||
``@Target`` indicates the kinds of class elements to which an annotation
|
||||
type is applicable. Then you could define one or more targets:
|
||||
|
||||
- ``CLASS`` Allowed in class docblocks
|
||||
- ``PROPERTY`` Allowed in property docblocks
|
||||
- ``METHOD`` Allowed in the method docblocks
|
||||
- ``FUNCTION`` Allowed in function dockblocks
|
||||
- ``ALL`` Allowed in class, property, method and function docblocks
|
||||
- ``ANNOTATION`` Allowed inside other annotations
|
||||
|
||||
If the annotations is not allowed in the current context, an
|
||||
``AnnotationException`` is thrown.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace MyCompany\Annotations;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target({"METHOD","PROPERTY"})
|
||||
*/
|
||||
class Bar
|
||||
{
|
||||
// some code
|
||||
}
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("CLASS")
|
||||
*/
|
||||
class Foo
|
||||
{
|
||||
// some code
|
||||
}
|
||||
|
||||
Attribute types
|
||||
---------------
|
||||
|
||||
The annotation parser checks the given parameters using the phpdoc
|
||||
annotation ``@var``, The data type could be validated using the ``@var``
|
||||
annotation on the annotation properties or using the ``@Attributes`` and
|
||||
``@Attribute`` annotations.
|
||||
|
||||
If the data type does not match you get an ``AnnotationException``
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace MyCompany\Annotations;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target({"METHOD","PROPERTY"})
|
||||
*/
|
||||
class Bar
|
||||
{
|
||||
/** @var mixed */
|
||||
public $mixed;
|
||||
|
||||
/** @var boolean */
|
||||
public $boolean;
|
||||
|
||||
/** @var bool */
|
||||
public $bool;
|
||||
|
||||
/** @var float */
|
||||
public $float;
|
||||
|
||||
/** @var string */
|
||||
public $string;
|
||||
|
||||
/** @var integer */
|
||||
public $integer;
|
||||
|
||||
/** @var array */
|
||||
public $array;
|
||||
|
||||
/** @var SomeAnnotationClass */
|
||||
public $annotation;
|
||||
|
||||
/** @var array<integer> */
|
||||
public $arrayOfIntegers;
|
||||
|
||||
/** @var array<SomeAnnotationClass> */
|
||||
public $arrayOfAnnotations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target({"METHOD","PROPERTY"})
|
||||
* @Attributes({
|
||||
* @Attribute("stringProperty", type = "string"),
|
||||
* @Attribute("annotProperty", type = "SomeAnnotationClass"),
|
||||
* })
|
||||
*/
|
||||
class Foo
|
||||
{
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->stringProperty = $values['stringProperty'];
|
||||
$this->annotProperty = $values['annotProperty'];
|
||||
}
|
||||
|
||||
// some code
|
||||
}
|
||||
|
||||
Annotation Required
|
||||
-------------------
|
||||
|
||||
``@Required`` indicates that the field must be specified when the
|
||||
annotation is used. If it is not used you get an ``AnnotationException``
|
||||
stating that this value can not be null.
|
||||
|
||||
Declaring a required field:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("ALL")
|
||||
*/
|
||||
class Foo
|
||||
{
|
||||
/** @Required */
|
||||
public $requiredField;
|
||||
}
|
||||
|
||||
Usage:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
/** @Foo(requiredField="value") */
|
||||
public $direction; // Valid
|
||||
|
||||
/** @Foo */
|
||||
public $direction; // Required field missing, throws an AnnotationException
|
||||
|
||||
|
||||
Enumerated values
|
||||
-----------------
|
||||
|
||||
- An annotation property marked with ``@Enum`` is a field that accepts a
|
||||
fixed set of scalar values.
|
||||
- You should use ``@Enum`` fields any time you need to represent fixed
|
||||
values.
|
||||
- The annotation parser checks the given value and throws an
|
||||
``AnnotationException`` if the value does not match.
|
||||
|
||||
|
||||
Declaring an enumerated property:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("ALL")
|
||||
*/
|
||||
class Direction
|
||||
{
|
||||
/**
|
||||
* @Enum({"NORTH", "SOUTH", "EAST", "WEST"})
|
||||
*/
|
||||
public $value;
|
||||
}
|
||||
|
||||
Annotation usage:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
/** @Direction("NORTH") */
|
||||
public $direction; // Valid value
|
||||
|
||||
/** @Direction("NORTHEAST") */
|
||||
public $direction; // Invalid value, throws an AnnotationException
|
||||
|
||||
|
||||
Constants
|
||||
---------
|
||||
|
||||
The use of constants and class constants is available on the annotations
|
||||
parser.
|
||||
|
||||
The following usages are allowed:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace MyCompany\Entity;
|
||||
|
||||
use MyCompany\Annotations\Foo;
|
||||
use MyCompany\Annotations\Bar;
|
||||
use MyCompany\Entity\SomeClass;
|
||||
|
||||
/**
|
||||
* @Foo(PHP_EOL)
|
||||
* @Bar(Bar::FOO)
|
||||
* @Foo({SomeClass::FOO, SomeClass::BAR})
|
||||
* @Bar({SomeClass::FOO_KEY = SomeClass::BAR_VALUE})
|
||||
*/
|
||||
class User
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Be careful with constants and the cache !
|
||||
|
||||
.. note::
|
||||
|
||||
The cached reader will not re-evaluate each time an annotation is
|
||||
loaded from cache. When a constant is changed the cache must be
|
||||
cleaned.
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Using the library API is simple. Using the annotations described in the
|
||||
previous section, you can now annotate other classes with your
|
||||
annotations:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace MyCompany\Entity;
|
||||
|
||||
use MyCompany\Annotations\Foo;
|
||||
use MyCompany\Annotations\Bar;
|
||||
|
||||
/**
|
||||
* @Foo(bar="foo")
|
||||
* @Bar(foo="bar")
|
||||
*/
|
||||
class User
|
||||
{
|
||||
}
|
||||
|
||||
Now we can write a script to get the annotations above:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$reflClass = new ReflectionClass('MyCompany\Entity\User');
|
||||
$classAnnotations = $reader->getClassAnnotations($reflClass);
|
||||
|
||||
foreach ($classAnnotations AS $annot) {
|
||||
if ($annot instanceof \MyCompany\Annotations\Foo) {
|
||||
echo $annot->bar; // prints "foo";
|
||||
} else if ($annot instanceof \MyCompany\Annotations\Bar) {
|
||||
echo $annot->foo; // prints "bar";
|
||||
}
|
||||
}
|
||||
|
||||
You have a complete API for retrieving annotation class instances from a
|
||||
class, property or method docblock:
|
||||
|
||||
|
||||
Reader API
|
||||
~~~~~~~~~~
|
||||
|
||||
Access all annotations of a class
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
public function getClassAnnotations(\ReflectionClass $class);
|
||||
|
||||
Access one annotation of a class
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
public function getClassAnnotation(\ReflectionClass $class, $annotationName);
|
||||
|
||||
Access all annotations of a method
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
public function getMethodAnnotations(\ReflectionMethod $method);
|
||||
|
||||
Access one annotation of a method
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName);
|
||||
|
||||
Access all annotations of a property
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
public function getPropertyAnnotations(\ReflectionProperty $property);
|
||||
|
||||
Access one annotation of a property
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName);
|
||||
|
||||
Access all annotations of a function
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
public function getFunctionAnnotations(\ReflectionFunction $property);
|
||||
|
||||
Access one annotation of a function
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
public function getFunctionAnnotation(\ReflectionFunction $property, $annotationName);
|
110
vendor/doctrine/annotations/docs/en/index.rst
vendored
Normal file
110
vendor/doctrine/annotations/docs/en/index.rst
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
Deprecation notice
|
||||
==================
|
||||
|
||||
PHP 8 introduced `attributes
|
||||
<https://www.php.net/manual/en/language.attributes.overview.php>`_,
|
||||
which are a native replacement for annotations. As such, this library is
|
||||
considered feature complete, and should receive exclusively bugfixes and
|
||||
security fixes.
|
||||
|
||||
Introduction
|
||||
============
|
||||
|
||||
Doctrine Annotations allows to implement custom annotation
|
||||
functionality for PHP classes and functions.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
class Foo
|
||||
{
|
||||
/**
|
||||
* @MyAnnotation(myProperty="value")
|
||||
*/
|
||||
private $bar;
|
||||
}
|
||||
|
||||
Annotations aren't implemented in PHP itself which is why this component
|
||||
offers a way to use the PHP doc-blocks as a place for the well known
|
||||
annotation syntax using the ``@`` char.
|
||||
|
||||
Annotations in Doctrine are used for the ORM configuration to build the
|
||||
class mapping, but it can be used in other projects for other purposes
|
||||
too.
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
You can install the Annotation component with composer:
|
||||
|
||||
.. code-block::
|
||||
|
||||
$ composer require doctrine/annotations
|
||||
|
||||
Create an annotation class
|
||||
==========================
|
||||
|
||||
An annotation class is a representation of the later used annotation
|
||||
configuration in classes. The annotation class of the previous example
|
||||
looks like this:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
final class MyAnnotation
|
||||
{
|
||||
public $myProperty;
|
||||
}
|
||||
|
||||
The annotation class is declared as an annotation by ``@Annotation``.
|
||||
|
||||
:ref:`Read more about custom annotations. <custom>`
|
||||
|
||||
Reading annotations
|
||||
===================
|
||||
|
||||
The access to the annotations happens by reflection of the class or function
|
||||
containing them. There are multiple reader-classes implementing the
|
||||
``Doctrine\Common\Annotations\Reader`` interface, that can access the
|
||||
annotations of a class. A common one is
|
||||
``Doctrine\Common\Annotations\AnnotationReader``:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
|
||||
// Deprecated and will be removed in 2.0 but currently needed
|
||||
AnnotationRegistry::registerLoader('class_exists');
|
||||
|
||||
$reflectionClass = new ReflectionClass(Foo::class);
|
||||
$property = $reflectionClass->getProperty('bar');
|
||||
|
||||
$reader = new AnnotationReader();
|
||||
$myAnnotation = $reader->getPropertyAnnotation(
|
||||
$property,
|
||||
MyAnnotation::class
|
||||
);
|
||||
|
||||
echo $myAnnotation->myProperty; // result: "value"
|
||||
|
||||
Note that ``AnnotationRegistry::registerLoader('class_exists')`` only works
|
||||
if you already have an autoloader configured (i.e. composer autoloader).
|
||||
Otherwise, :ref:`please take a look to the other annotation autoload mechanisms <annotations>`.
|
||||
|
||||
A reader has multiple methods to access the annotations of a class or
|
||||
function.
|
||||
|
||||
:ref:`Read more about handling annotations. <annotations>`
|
||||
|
||||
IDE Support
|
||||
-----------
|
||||
|
||||
Some IDEs already provide support for annotations:
|
||||
|
||||
- Eclipse via the `Symfony2 Plugin <https://github.com/pulse00/Symfony-2-Eclipse-Plugin>`_
|
||||
- PhpStorm via the `PHP Annotations Plugin <https://plugins.jetbrains.com/plugin/7320-php-annotations>`_ or the `Symfony Plugin <https://plugins.jetbrains.com/plugin/7219-symfony-support>`_
|
||||
|
||||
.. _Read more about handling annotations.: annotations
|
||||
.. _Read more about custom annotations.: custom
|
6
vendor/doctrine/annotations/docs/en/sidebar.rst
vendored
Normal file
6
vendor/doctrine/annotations/docs/en/sidebar.rst
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
.. toctree::
|
||||
:depth: 3
|
||||
|
||||
index
|
||||
annotations
|
||||
custom
|
57
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation.php
vendored
Normal file
57
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation.php
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use BadMethodCallException;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Annotations class.
|
||||
*/
|
||||
class Annotation
|
||||
{
|
||||
/**
|
||||
* Value property. Common among all derived classes.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/** @param array<string, mixed> $data Key-value for properties to be defined in this class. */
|
||||
final public function __construct(array $data)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error handler for unknown property accessor in Annotation class.
|
||||
*
|
||||
* @param string $name Unknown property name.
|
||||
*
|
||||
* @throws BadMethodCallException
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
throw new BadMethodCallException(
|
||||
sprintf("Unknown property '%s' on annotation '%s'.", $name, static::class)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error handler for unknown property mutator in Annotation class.
|
||||
*
|
||||
* @param string $name Unknown property name.
|
||||
* @param mixed $value Property value.
|
||||
*
|
||||
* @throws BadMethodCallException
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
throw new BadMethodCallException(
|
||||
sprintf("Unknown property '%s' on annotation '%s'.", $name, static::class)
|
||||
);
|
||||
}
|
||||
}
|
21
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attribute.php
vendored
Normal file
21
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attribute.php
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the attribute type during the parsing process.
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Attribute
|
||||
{
|
||||
/** @var string */
|
||||
public $name;
|
||||
|
||||
/** @var string */
|
||||
public $type;
|
||||
|
||||
/** @var bool */
|
||||
public $required = false;
|
||||
}
|
15
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attributes.php
vendored
Normal file
15
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attributes.php
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the types of all declared attributes during the parsing process.
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Attributes
|
||||
{
|
||||
/** @var array<Attribute> */
|
||||
public $value;
|
||||
}
|
69
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Enum.php
vendored
Normal file
69
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Enum.php
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function in_array;
|
||||
use function is_object;
|
||||
use function is_scalar;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the available values during the parsing process.
|
||||
*
|
||||
* @Annotation
|
||||
* @Attributes({
|
||||
* @Attribute("value", required = true, type = "array"),
|
||||
* @Attribute("literal", required = false, type = "array")
|
||||
* })
|
||||
*/
|
||||
final class Enum
|
||||
{
|
||||
/** @phpstan-var list<scalar> */
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Literal target declaration.
|
||||
*
|
||||
* @var mixed[]
|
||||
*/
|
||||
public $literal;
|
||||
|
||||
/**
|
||||
* @phpstan-param array{literal?: mixed[], value: list<scalar>} $values
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
if (! isset($values['literal'])) {
|
||||
$values['literal'] = [];
|
||||
}
|
||||
|
||||
foreach ($values['value'] as $var) {
|
||||
if (! is_scalar($var)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'@Enum supports only scalar values "%s" given.',
|
||||
is_object($var) ? get_class($var) : gettype($var)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($values['literal'] as $key => $var) {
|
||||
if (! in_array($key, $values['value'])) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Undefined enumerator value "%s" for literal "%s".',
|
||||
$key,
|
||||
$var
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$this->value = $values['value'];
|
||||
$this->literal = $values['literal'];
|
||||
}
|
||||
}
|
43
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php
vendored
Normal file
43
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
use function is_array;
|
||||
use function is_string;
|
||||
use function json_encode;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser to ignore specific
|
||||
* annotations during the parsing process.
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class IgnoreAnnotation
|
||||
{
|
||||
/** @phpstan-var list<string> */
|
||||
public $names;
|
||||
|
||||
/**
|
||||
* @phpstan-param array{value: string|list<string>} $values
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
if (is_string($values['value'])) {
|
||||
$values['value'] = [$values['value']];
|
||||
}
|
||||
|
||||
if (! is_array($values['value'])) {
|
||||
throw new RuntimeException(sprintf(
|
||||
'@IgnoreAnnotation expects either a string name, or an array of strings, but got %s.',
|
||||
json_encode($values['value'])
|
||||
));
|
||||
}
|
||||
|
||||
$this->names = $values['value'];
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that indicates that the annotated class should be constructed with a named argument call.
|
||||
*
|
||||
* @Annotation
|
||||
* @Target("CLASS")
|
||||
*/
|
||||
final class NamedArgumentConstructor
|
||||
{
|
||||
}
|
13
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Required.php
vendored
Normal file
13
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Required.php
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check if that attribute is required during the parsing process.
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Required
|
||||
{
|
||||
}
|
101
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php
vendored
Normal file
101
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
use function array_keys;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the annotation target during the parsing process.
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Target
|
||||
{
|
||||
public const TARGET_CLASS = 1;
|
||||
public const TARGET_METHOD = 2;
|
||||
public const TARGET_PROPERTY = 4;
|
||||
public const TARGET_ANNOTATION = 8;
|
||||
public const TARGET_FUNCTION = 16;
|
||||
public const TARGET_ALL = 31;
|
||||
|
||||
/** @var array<string, int> */
|
||||
private static $map = [
|
||||
'ALL' => self::TARGET_ALL,
|
||||
'CLASS' => self::TARGET_CLASS,
|
||||
'METHOD' => self::TARGET_METHOD,
|
||||
'PROPERTY' => self::TARGET_PROPERTY,
|
||||
'FUNCTION' => self::TARGET_FUNCTION,
|
||||
'ANNOTATION' => self::TARGET_ANNOTATION,
|
||||
];
|
||||
|
||||
/** @phpstan-var list<string> */
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Targets as bitmask.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $targets;
|
||||
|
||||
/**
|
||||
* Literal target declaration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $literal;
|
||||
|
||||
/**
|
||||
* @phpstan-param array{value?: string|list<string>} $values
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
if (! isset($values['value'])) {
|
||||
$values['value'] = null;
|
||||
}
|
||||
|
||||
if (is_string($values['value'])) {
|
||||
$values['value'] = [$values['value']];
|
||||
}
|
||||
|
||||
if (! is_array($values['value'])) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'@Target expects either a string value, or an array of strings, "%s" given.',
|
||||
is_object($values['value']) ? get_class($values['value']) : gettype($values['value'])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$bitmask = 0;
|
||||
foreach ($values['value'] as $literal) {
|
||||
if (! isset(self::$map[$literal])) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'Invalid Target "%s". Available targets: [%s]',
|
||||
$literal,
|
||||
implode(', ', array_keys(self::$map))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$bitmask |= self::$map[$literal];
|
||||
}
|
||||
|
||||
$this->targets = $bitmask;
|
||||
$this->value = $values['value'];
|
||||
$this->literal = implode(', ', $this->value);
|
||||
}
|
||||
}
|
167
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php
vendored
Normal file
167
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php
vendored
Normal file
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function implode;
|
||||
use function is_object;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Description of AnnotationException
|
||||
*/
|
||||
class AnnotationException extends Exception
|
||||
{
|
||||
/**
|
||||
* Creates a new AnnotationException describing a Syntax error.
|
||||
*
|
||||
* @param string $message Exception message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function syntaxError($message)
|
||||
{
|
||||
return new self('[Syntax Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a Semantical error.
|
||||
*
|
||||
* @param string $message Exception message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function semanticalError($message)
|
||||
{
|
||||
return new self('[Semantical Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing an error which occurred during
|
||||
* the creation of the annotation.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function creationError($message, ?Throwable $previous = null)
|
||||
{
|
||||
return new self('[Creation Error] ' . $message, 0, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a type error.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function typeError($message)
|
||||
{
|
||||
return new self('[Type Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a constant semantical error.
|
||||
*
|
||||
* @param string $identifier
|
||||
* @param string $context
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function semanticalErrorConstants($identifier, $context = null)
|
||||
{
|
||||
return self::semanticalError(sprintf(
|
||||
"Couldn't find constant %s%s.",
|
||||
$identifier,
|
||||
$context ? ', ' . $context : ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing an type error of an attribute.
|
||||
*
|
||||
* @param string $attributeName
|
||||
* @param string $annotationName
|
||||
* @param string $context
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function attributeTypeError($attributeName, $annotationName, $context, $expected, $actual)
|
||||
{
|
||||
return self::typeError(sprintf(
|
||||
'Attribute "%s" of @%s declared on %s expects %s, but got %s.',
|
||||
$attributeName,
|
||||
$annotationName,
|
||||
$context,
|
||||
$expected,
|
||||
is_object($actual) ? 'an instance of ' . get_class($actual) : gettype($actual)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing an required error of an attribute.
|
||||
*
|
||||
* @param string $attributeName
|
||||
* @param string $annotationName
|
||||
* @param string $context
|
||||
* @param string $expected
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function requiredError($attributeName, $annotationName, $context, $expected)
|
||||
{
|
||||
return self::typeError(sprintf(
|
||||
'Attribute "%s" of @%s declared on %s expects %s. This value should not be null.',
|
||||
$attributeName,
|
||||
$annotationName,
|
||||
$context,
|
||||
$expected
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a invalid enummerator.
|
||||
*
|
||||
* @param string $attributeName
|
||||
* @param string $annotationName
|
||||
* @param string $context
|
||||
* @param mixed $given
|
||||
* @phpstan-param list<string> $available
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function enumeratorError($attributeName, $annotationName, $context, $available, $given)
|
||||
{
|
||||
return new self(sprintf(
|
||||
'[Enum Error] Attribute "%s" of @%s declared on %s accepts only [%s], but got %s.',
|
||||
$attributeName,
|
||||
$annotationName,
|
||||
$context,
|
||||
implode(', ', $available),
|
||||
is_object($given) ? get_class($given) : $given
|
||||
));
|
||||
}
|
||||
|
||||
/** @return AnnotationException */
|
||||
public static function optimizerPlusSaveComments()
|
||||
{
|
||||
return new self(
|
||||
'You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1.'
|
||||
);
|
||||
}
|
||||
|
||||
/** @return AnnotationException */
|
||||
public static function optimizerPlusLoadComments()
|
||||
{
|
||||
return new self(
|
||||
'You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1.'
|
||||
);
|
||||
}
|
||||
}
|
389
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php
vendored
Normal file
389
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php
vendored
Normal file
@ -0,0 +1,389 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ReflectionClass;
|
||||
use ReflectionFunction;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
|
||||
use function array_merge;
|
||||
use function class_exists;
|
||||
use function extension_loaded;
|
||||
use function ini_get;
|
||||
|
||||
/**
|
||||
* A reader for docblock annotations.
|
||||
*/
|
||||
class AnnotationReader implements Reader
|
||||
{
|
||||
/**
|
||||
* Global map for imports.
|
||||
*
|
||||
* @var array<string, class-string>
|
||||
*/
|
||||
private static $globalImports = [
|
||||
'ignoreannotation' => Annotation\IgnoreAnnotation::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* A list with annotations that are not causing exceptions when not resolved to an annotation class.
|
||||
*
|
||||
* The names are case sensitive.
|
||||
*
|
||||
* @var array<string, true>
|
||||
*/
|
||||
private static $globalIgnoredNames = ImplicitlyIgnoredAnnotationNames::LIST;
|
||||
|
||||
/**
|
||||
* A list with annotations that are not causing exceptions when not resolved to an annotation class.
|
||||
*
|
||||
* The names are case sensitive.
|
||||
*
|
||||
* @var array<string, true>
|
||||
*/
|
||||
private static $globalIgnoredNamespaces = [];
|
||||
|
||||
/**
|
||||
* Add a new annotation to the globally ignored annotation names with regard to exception handling.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public static function addGlobalIgnoredName($name)
|
||||
{
|
||||
self::$globalIgnoredNames[$name] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new annotation to the globally ignored annotation namespaces with regard to exception handling.
|
||||
*
|
||||
* @param string $namespace
|
||||
*/
|
||||
public static function addGlobalIgnoredNamespace($namespace)
|
||||
{
|
||||
self::$globalIgnoredNamespaces[$namespace] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotations parser.
|
||||
*
|
||||
* @var DocParser
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* Annotations parser used to collect parsing metadata.
|
||||
*
|
||||
* @var DocParser
|
||||
*/
|
||||
private $preParser;
|
||||
|
||||
/**
|
||||
* PHP parser used to collect imports.
|
||||
*
|
||||
* @var PhpParser
|
||||
*/
|
||||
private $phpParser;
|
||||
|
||||
/**
|
||||
* In-memory cache mechanism to store imported annotations per class.
|
||||
*
|
||||
* @psalm-var array<'class'|'function', array<string, array<string, class-string>>>
|
||||
*/
|
||||
private $imports = [];
|
||||
|
||||
/**
|
||||
* In-memory cache mechanism to store ignored annotations per class.
|
||||
*
|
||||
* @psalm-var array<'class'|'function', array<string, array<string, true>>>
|
||||
*/
|
||||
private $ignoredAnnotationNames = [];
|
||||
|
||||
/**
|
||||
* Initializes a new AnnotationReader.
|
||||
*
|
||||
* @throws AnnotationException
|
||||
*/
|
||||
public function __construct(?DocParser $parser = null)
|
||||
{
|
||||
if (
|
||||
extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.save_comments') === '0' ||
|
||||
ini_get('opcache.save_comments') === '0')
|
||||
) {
|
||||
throw AnnotationException::optimizerPlusSaveComments();
|
||||
}
|
||||
|
||||
if (extension_loaded('Zend OPcache') && ini_get('opcache.save_comments') === 0) {
|
||||
throw AnnotationException::optimizerPlusSaveComments();
|
||||
}
|
||||
|
||||
// Make sure that the IgnoreAnnotation annotation is loaded
|
||||
class_exists(IgnoreAnnotation::class);
|
||||
|
||||
$this->parser = $parser ?: new DocParser();
|
||||
|
||||
$this->preParser = new DocParser();
|
||||
|
||||
$this->preParser->setImports(self::$globalImports);
|
||||
$this->preParser->setIgnoreNotImportedAnnotations(true);
|
||||
$this->preParser->setIgnoredAnnotationNames(self::$globalIgnoredNames);
|
||||
|
||||
$this->phpParser = new PhpParser();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(ReflectionClass $class)
|
||||
{
|
||||
$this->parser->setTarget(Target::TARGET_CLASS);
|
||||
$this->parser->setImports($this->getImports($class));
|
||||
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
|
||||
$this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
|
||||
|
||||
return $this->parser->parse($class->getDocComment(), 'class ' . $class->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(ReflectionClass $class, $annotationName)
|
||||
{
|
||||
$annotations = $this->getClassAnnotations($class);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
$context = 'property ' . $class->getName() . '::$' . $property->getName();
|
||||
|
||||
$this->parser->setTarget(Target::TARGET_PROPERTY);
|
||||
$this->parser->setImports($this->getPropertyImports($property));
|
||||
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
|
||||
$this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
|
||||
|
||||
return $this->parser->parse($property->getDocComment(), $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
$annotations = $this->getPropertyAnnotations($property);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
$context = 'method ' . $class->getName() . '::' . $method->getName() . '()';
|
||||
|
||||
$this->parser->setTarget(Target::TARGET_METHOD);
|
||||
$this->parser->setImports($this->getMethodImports($method));
|
||||
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
|
||||
$this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
|
||||
|
||||
return $this->parser->parse($method->getDocComment(), $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
$annotations = $this->getMethodAnnotations($method);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the annotations applied to a function.
|
||||
*
|
||||
* @phpstan-return list<object> An array of Annotations.
|
||||
*/
|
||||
public function getFunctionAnnotations(ReflectionFunction $function): array
|
||||
{
|
||||
$context = 'function ' . $function->getName();
|
||||
|
||||
$this->parser->setTarget(Target::TARGET_FUNCTION);
|
||||
$this->parser->setImports($this->getImports($function));
|
||||
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($function));
|
||||
$this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
|
||||
|
||||
return $this->parser->parse($function->getDocComment(), $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a function annotation.
|
||||
*
|
||||
* @return object|null The Annotation or NULL, if the requested annotation does not exist.
|
||||
*/
|
||||
public function getFunctionAnnotation(ReflectionFunction $function, string $annotationName)
|
||||
{
|
||||
$annotations = $this->getFunctionAnnotations($function);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ignored annotations for the given class or function.
|
||||
*
|
||||
* @param ReflectionClass|ReflectionFunction $reflection
|
||||
*
|
||||
* @return array<string, true>
|
||||
*/
|
||||
private function getIgnoredAnnotationNames($reflection): array
|
||||
{
|
||||
$type = $reflection instanceof ReflectionClass ? 'class' : 'function';
|
||||
$name = $reflection->getName();
|
||||
|
||||
if (isset($this->ignoredAnnotationNames[$type][$name])) {
|
||||
return $this->ignoredAnnotationNames[$type][$name];
|
||||
}
|
||||
|
||||
$this->collectParsingMetadata($reflection);
|
||||
|
||||
return $this->ignoredAnnotationNames[$type][$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves imports for a class or a function.
|
||||
*
|
||||
* @param ReflectionClass|ReflectionFunction $reflection
|
||||
*
|
||||
* @return array<string, class-string>
|
||||
*/
|
||||
private function getImports($reflection): array
|
||||
{
|
||||
$type = $reflection instanceof ReflectionClass ? 'class' : 'function';
|
||||
$name = $reflection->getName();
|
||||
|
||||
if (isset($this->imports[$type][$name])) {
|
||||
return $this->imports[$type][$name];
|
||||
}
|
||||
|
||||
$this->collectParsingMetadata($reflection);
|
||||
|
||||
return $this->imports[$type][$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves imports for methods.
|
||||
*
|
||||
* @return array<string, class-string>
|
||||
*/
|
||||
private function getMethodImports(ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
$classImports = $this->getImports($class);
|
||||
|
||||
$traitImports = [];
|
||||
|
||||
foreach ($class->getTraits() as $trait) {
|
||||
if (
|
||||
! $trait->hasMethod($method->getName())
|
||||
|| $trait->getFileName() !== $method->getFileName()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$traitImports = array_merge($traitImports, $this->phpParser->parseUseStatements($trait));
|
||||
}
|
||||
|
||||
return array_merge($classImports, $traitImports);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves imports for properties.
|
||||
*
|
||||
* @return array<string, class-string>
|
||||
*/
|
||||
private function getPropertyImports(ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
$classImports = $this->getImports($class);
|
||||
|
||||
$traitImports = [];
|
||||
|
||||
foreach ($class->getTraits() as $trait) {
|
||||
if (! $trait->hasProperty($property->getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$traitImports = array_merge($traitImports, $this->phpParser->parseUseStatements($trait));
|
||||
}
|
||||
|
||||
return array_merge($classImports, $traitImports);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects parsing metadata for a given class or function.
|
||||
*
|
||||
* @param ReflectionClass|ReflectionFunction $reflection
|
||||
*/
|
||||
private function collectParsingMetadata($reflection): void
|
||||
{
|
||||
$type = $reflection instanceof ReflectionClass ? 'class' : 'function';
|
||||
$name = $reflection->getName();
|
||||
|
||||
$ignoredAnnotationNames = self::$globalIgnoredNames;
|
||||
$annotations = $this->preParser->parse($reflection->getDocComment(), $type . ' ' . $name);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if (! ($annotation instanceof IgnoreAnnotation)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($annotation->names as $annot) {
|
||||
$ignoredAnnotationNames[$annot] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->imports[$type][$name] = array_merge(
|
||||
self::$globalImports,
|
||||
$this->phpParser->parseUseStatements($reflection),
|
||||
[
|
||||
'__NAMESPACE__' => $reflection->getNamespaceName(),
|
||||
'self' => $name,
|
||||
]
|
||||
);
|
||||
|
||||
$this->ignoredAnnotationNames[$type][$name] = $ignoredAnnotationNames;
|
||||
}
|
||||
}
|
190
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php
vendored
Normal file
190
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php
vendored
Normal file
@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use function array_key_exists;
|
||||
use function array_merge;
|
||||
use function class_exists;
|
||||
use function in_array;
|
||||
use function is_file;
|
||||
use function str_replace;
|
||||
use function stream_resolve_include_path;
|
||||
use function strpos;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
final class AnnotationRegistry
|
||||
{
|
||||
/**
|
||||
* A map of namespaces to use for autoloading purposes based on a PSR-0 convention.
|
||||
*
|
||||
* Contains the namespace as key and an array of directories as value. If the value is NULL
|
||||
* the include path is used for checking for the corresponding file.
|
||||
*
|
||||
* This autoloading mechanism does not utilize the PHP autoloading but implements autoloading on its own.
|
||||
*
|
||||
* @var string[][]|string[]|null[]
|
||||
*/
|
||||
private static $autoloadNamespaces = [];
|
||||
|
||||
/**
|
||||
* A map of autoloader callables.
|
||||
*
|
||||
* @var callable[]
|
||||
*/
|
||||
private static $loaders = [];
|
||||
|
||||
/**
|
||||
* An array of classes which cannot be found
|
||||
*
|
||||
* @var null[] indexed by class name
|
||||
*/
|
||||
private static $failedToAutoload = [];
|
||||
|
||||
/**
|
||||
* Whenever registerFile() was used. Disables use of standard autoloader.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private static $registerFileUsed = false;
|
||||
|
||||
public static function reset(): void
|
||||
{
|
||||
self::$autoloadNamespaces = [];
|
||||
self::$loaders = [];
|
||||
self::$failedToAutoload = [];
|
||||
self::$registerFileUsed = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers file.
|
||||
*
|
||||
* @deprecated This method is deprecated and will be removed in
|
||||
* doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
|
||||
*/
|
||||
public static function registerFile(string $file): void
|
||||
{
|
||||
self::$registerFileUsed = true;
|
||||
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a namespace with one or many directories to look for files or null for the include path.
|
||||
*
|
||||
* Loading of this namespaces will be done with a PSR-0 namespace loading algorithm.
|
||||
*
|
||||
* @deprecated This method is deprecated and will be removed in
|
||||
* doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
|
||||
*
|
||||
* @phpstan-param string|list<string>|null $dirs
|
||||
*/
|
||||
public static function registerAutoloadNamespace(string $namespace, $dirs = null): void
|
||||
{
|
||||
self::$autoloadNamespaces[$namespace] = $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers multiple namespaces.
|
||||
*
|
||||
* Loading of this namespaces will be done with a PSR-0 namespace loading algorithm.
|
||||
*
|
||||
* @deprecated This method is deprecated and will be removed in
|
||||
* doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
|
||||
*
|
||||
* @param string[][]|string[]|null[] $namespaces indexed by namespace name
|
||||
*/
|
||||
public static function registerAutoloadNamespaces(array $namespaces): void
|
||||
{
|
||||
self::$autoloadNamespaces = array_merge(self::$autoloadNamespaces, $namespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an autoloading callable for annotations, much like spl_autoload_register().
|
||||
*
|
||||
* NOTE: These class loaders HAVE to be silent when a class was not found!
|
||||
* IMPORTANT: Loaders have to return true if they loaded a class that could contain the searched annotation class.
|
||||
*
|
||||
* @deprecated This method is deprecated and will be removed in
|
||||
* doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
|
||||
*/
|
||||
public static function registerLoader(callable $callable): void
|
||||
{
|
||||
// Reset our static cache now that we have a new loader to work with
|
||||
self::$failedToAutoload = [];
|
||||
self::$loaders[] = $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an autoloading callable for annotations, if it is not already registered
|
||||
*
|
||||
* @deprecated This method is deprecated and will be removed in
|
||||
* doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
|
||||
*/
|
||||
public static function registerUniqueLoader(callable $callable): void
|
||||
{
|
||||
if (in_array($callable, self::$loaders, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::registerLoader($callable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoloads an annotation class silently.
|
||||
*/
|
||||
public static function loadAnnotationClass(string $class): bool
|
||||
{
|
||||
if (class_exists($class, false)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (array_key_exists($class, self::$failedToAutoload)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (self::$autoloadNamespaces as $namespace => $dirs) {
|
||||
if (strpos($class, $namespace) !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$file = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
|
||||
|
||||
if ($dirs === null) {
|
||||
$path = stream_resolve_include_path($file);
|
||||
if ($path) {
|
||||
require $path;
|
||||
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
foreach ((array) $dirs as $dir) {
|
||||
if (is_file($dir . DIRECTORY_SEPARATOR . $file)) {
|
||||
require $dir . DIRECTORY_SEPARATOR . $file;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (self::$loaders as $loader) {
|
||||
if ($loader($class) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
self::$loaders === [] &&
|
||||
self::$autoloadNamespaces === [] &&
|
||||
self::$registerFileUsed === false &&
|
||||
class_exists($class)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
self::$failedToAutoload[$class] = null;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
266
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/CachedReader.php
vendored
Normal file
266
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/CachedReader.php
vendored
Normal file
@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function assert;
|
||||
use function filemtime;
|
||||
use function max;
|
||||
use function time;
|
||||
|
||||
/**
|
||||
* A cache aware annotation reader.
|
||||
*
|
||||
* @deprecated the CachedReader is deprecated and will be removed
|
||||
* in version 2.0.0 of doctrine/annotations. Please use the
|
||||
* {@see \Doctrine\Common\Annotations\PsrCachedReader} instead.
|
||||
*/
|
||||
final class CachedReader implements Reader
|
||||
{
|
||||
/** @var Reader */
|
||||
private $delegate;
|
||||
|
||||
/** @var Cache */
|
||||
private $cache;
|
||||
|
||||
/** @var bool */
|
||||
private $debug;
|
||||
|
||||
/** @var array<string, array<object>> */
|
||||
private $loadedAnnotations = [];
|
||||
|
||||
/** @var int[] */
|
||||
private $loadedFilemtimes = [];
|
||||
|
||||
/** @param bool $debug */
|
||||
public function __construct(Reader $reader, Cache $cache, $debug = false)
|
||||
{
|
||||
$this->delegate = $reader;
|
||||
$this->cache = $cache;
|
||||
$this->debug = (bool) $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(ReflectionClass $class)
|
||||
{
|
||||
$cacheKey = $class->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$cacheKey])) {
|
||||
return $this->loadedAnnotations[$cacheKey];
|
||||
}
|
||||
|
||||
$annots = $this->fetchFromCache($cacheKey, $class);
|
||||
if ($annots === false) {
|
||||
$annots = $this->delegate->getClassAnnotations($class);
|
||||
$this->saveToCache($cacheKey, $annots);
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$cacheKey] = $annots;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(ReflectionClass $class, $annotationName)
|
||||
{
|
||||
foreach ($this->getClassAnnotations($class) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
$cacheKey = $class->getName() . '$' . $property->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$cacheKey])) {
|
||||
return $this->loadedAnnotations[$cacheKey];
|
||||
}
|
||||
|
||||
$annots = $this->fetchFromCache($cacheKey, $class);
|
||||
if ($annots === false) {
|
||||
$annots = $this->delegate->getPropertyAnnotations($property);
|
||||
$this->saveToCache($cacheKey, $annots);
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$cacheKey] = $annots;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
foreach ($this->getPropertyAnnotations($property) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
$cacheKey = $class->getName() . '#' . $method->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$cacheKey])) {
|
||||
return $this->loadedAnnotations[$cacheKey];
|
||||
}
|
||||
|
||||
$annots = $this->fetchFromCache($cacheKey, $class);
|
||||
if ($annots === false) {
|
||||
$annots = $this->delegate->getMethodAnnotations($method);
|
||||
$this->saveToCache($cacheKey, $annots);
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$cacheKey] = $annots;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
foreach ($this->getMethodAnnotations($method) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears loaded annotations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearLoadedAnnotations()
|
||||
{
|
||||
$this->loadedAnnotations = [];
|
||||
$this->loadedFilemtimes = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a value from the cache.
|
||||
*
|
||||
* @param string $cacheKey The cache key.
|
||||
*
|
||||
* @return mixed The cached value or false when the value is not in cache.
|
||||
*/
|
||||
private function fetchFromCache($cacheKey, ReflectionClass $class)
|
||||
{
|
||||
$data = $this->cache->fetch($cacheKey);
|
||||
if ($data !== false) {
|
||||
if (! $this->debug || $this->isCacheFresh($cacheKey, $class)) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a value to the cache.
|
||||
*
|
||||
* @param string $cacheKey The cache key.
|
||||
* @param mixed $value The value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function saveToCache($cacheKey, $value)
|
||||
{
|
||||
$this->cache->save($cacheKey, $value);
|
||||
if (! $this->debug) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->cache->save('[C]' . $cacheKey, time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the cache is fresh.
|
||||
*
|
||||
* @param string $cacheKey
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isCacheFresh($cacheKey, ReflectionClass $class)
|
||||
{
|
||||
$lastModification = $this->getLastModification($class);
|
||||
if ($lastModification === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->cache->fetch('[C]' . $cacheKey) >= $lastModification;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time the class was last modified, testing traits and parents
|
||||
*/
|
||||
private function getLastModification(ReflectionClass $class): int
|
||||
{
|
||||
$filename = $class->getFileName();
|
||||
|
||||
if (isset($this->loadedFilemtimes[$filename])) {
|
||||
return $this->loadedFilemtimes[$filename];
|
||||
}
|
||||
|
||||
$parent = $class->getParentClass();
|
||||
|
||||
$lastModification = max(array_merge(
|
||||
[$filename ? filemtime($filename) : 0],
|
||||
array_map(function (ReflectionClass $reflectionTrait): int {
|
||||
return $this->getTraitLastModificationTime($reflectionTrait);
|
||||
}, $class->getTraits()),
|
||||
array_map(function (ReflectionClass $class): int {
|
||||
return $this->getLastModification($class);
|
||||
}, $class->getInterfaces()),
|
||||
$parent ? [$this->getLastModification($parent)] : []
|
||||
));
|
||||
|
||||
assert($lastModification !== false);
|
||||
|
||||
return $this->loadedFilemtimes[$filename] = $lastModification;
|
||||
}
|
||||
|
||||
private function getTraitLastModificationTime(ReflectionClass $reflectionTrait): int
|
||||
{
|
||||
$fileName = $reflectionTrait->getFileName();
|
||||
|
||||
if (isset($this->loadedFilemtimes[$fileName])) {
|
||||
return $this->loadedFilemtimes[$fileName];
|
||||
}
|
||||
|
||||
$lastModificationTime = max(array_merge(
|
||||
[$fileName ? filemtime($fileName) : 0],
|
||||
array_map(function (ReflectionClass $reflectionTrait): int {
|
||||
return $this->getTraitLastModificationTime($reflectionTrait);
|
||||
}, $reflectionTrait->getTraits())
|
||||
));
|
||||
|
||||
assert($lastModificationTime !== false);
|
||||
|
||||
return $this->loadedFilemtimes[$fileName] = $lastModificationTime;
|
||||
}
|
||||
}
|
143
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocLexer.php
vendored
Normal file
143
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocLexer.php
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use Doctrine\Common\Lexer\AbstractLexer;
|
||||
|
||||
use function ctype_alpha;
|
||||
use function is_numeric;
|
||||
use function str_replace;
|
||||
use function stripos;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
* Simple lexer for docblock annotations.
|
||||
*
|
||||
* @template-extends AbstractLexer<DocLexer::T_*, string>
|
||||
*/
|
||||
final class DocLexer extends AbstractLexer
|
||||
{
|
||||
public const T_NONE = 1;
|
||||
public const T_INTEGER = 2;
|
||||
public const T_STRING = 3;
|
||||
public const T_FLOAT = 4;
|
||||
|
||||
// All tokens that are also identifiers should be >= 100
|
||||
public const T_IDENTIFIER = 100;
|
||||
public const T_AT = 101;
|
||||
public const T_CLOSE_CURLY_BRACES = 102;
|
||||
public const T_CLOSE_PARENTHESIS = 103;
|
||||
public const T_COMMA = 104;
|
||||
public const T_EQUALS = 105;
|
||||
public const T_FALSE = 106;
|
||||
public const T_NAMESPACE_SEPARATOR = 107;
|
||||
public const T_OPEN_CURLY_BRACES = 108;
|
||||
public const T_OPEN_PARENTHESIS = 109;
|
||||
public const T_TRUE = 110;
|
||||
public const T_NULL = 111;
|
||||
public const T_COLON = 112;
|
||||
public const T_MINUS = 113;
|
||||
|
||||
/** @var array<string, self::T*> */
|
||||
protected $noCase = [
|
||||
'@' => self::T_AT,
|
||||
',' => self::T_COMMA,
|
||||
'(' => self::T_OPEN_PARENTHESIS,
|
||||
')' => self::T_CLOSE_PARENTHESIS,
|
||||
'{' => self::T_OPEN_CURLY_BRACES,
|
||||
'}' => self::T_CLOSE_CURLY_BRACES,
|
||||
'=' => self::T_EQUALS,
|
||||
':' => self::T_COLON,
|
||||
'-' => self::T_MINUS,
|
||||
'\\' => self::T_NAMESPACE_SEPARATOR,
|
||||
];
|
||||
|
||||
/** @var array<string, self::T*> */
|
||||
protected $withCase = [
|
||||
'true' => self::T_TRUE,
|
||||
'false' => self::T_FALSE,
|
||||
'null' => self::T_NULL,
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether the next token starts immediately, or if there were
|
||||
* non-captured symbols before that
|
||||
*/
|
||||
public function nextTokenIsAdjacent(): bool
|
||||
{
|
||||
return $this->token === null
|
||||
|| ($this->lookahead !== null
|
||||
&& ($this->lookahead['position'] - $this->token['position']) === strlen($this->token['value']));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getCatchablePatterns()
|
||||
{
|
||||
return [
|
||||
'[a-z_\\\][a-z0-9_\:\\\]*[a-z_][a-z0-9_]*',
|
||||
'(?:[+-]?[0-9]+(?:[\.][0-9]+)*)(?:[eE][+-]?[0-9]+)?',
|
||||
'"(?:""|[^"])*+"',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNonCatchablePatterns()
|
||||
{
|
||||
return ['\s+', '\*+', '(.)'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getType(&$value)
|
||||
{
|
||||
$type = self::T_NONE;
|
||||
|
||||
if ($value[0] === '"') {
|
||||
$value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));
|
||||
|
||||
return self::T_STRING;
|
||||
}
|
||||
|
||||
if (isset($this->noCase[$value])) {
|
||||
return $this->noCase[$value];
|
||||
}
|
||||
|
||||
if ($value[0] === '_' || $value[0] === '\\' || ctype_alpha($value[0])) {
|
||||
return self::T_IDENTIFIER;
|
||||
}
|
||||
|
||||
$lowerValue = strtolower($value);
|
||||
|
||||
if (isset($this->withCase[$lowerValue])) {
|
||||
return $this->withCase[$lowerValue];
|
||||
}
|
||||
|
||||
// Checking numeric value
|
||||
if (is_numeric($value)) {
|
||||
return strpos($value, '.') !== false || stripos($value, 'e') !== false
|
||||
? self::T_FLOAT : self::T_INTEGER;
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
/** @return array{value: int|string, type:self::T_*|null, position:int} */
|
||||
public function peek(): ?array
|
||||
{
|
||||
$token = parent::peek();
|
||||
|
||||
if ($token === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (array) $token;
|
||||
}
|
||||
}
|
1485
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php
vendored
Normal file
1485
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php
vendored
Normal file
@ -0,0 +1,1485 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Attribute;
|
||||
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||
use Doctrine\Common\Annotations\Annotation\Enum;
|
||||
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use ReflectionProperty;
|
||||
use RuntimeException;
|
||||
use stdClass;
|
||||
use Throwable;
|
||||
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
use function array_pop;
|
||||
use function array_values;
|
||||
use function class_exists;
|
||||
use function constant;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function explode;
|
||||
use function gettype;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function interface_exists;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function json_encode;
|
||||
use function ltrim;
|
||||
use function preg_match;
|
||||
use function reset;
|
||||
use function rtrim;
|
||||
use function sprintf;
|
||||
use function stripos;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function strrpos;
|
||||
use function strtolower;
|
||||
use function substr;
|
||||
use function trim;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
/**
|
||||
* A parser for docblock annotations.
|
||||
*
|
||||
* It is strongly discouraged to change the default annotation parsing process.
|
||||
*/
|
||||
final class DocParser
|
||||
{
|
||||
/**
|
||||
* An array of all valid tokens for a class name.
|
||||
*
|
||||
* @phpstan-var list<int>
|
||||
*/
|
||||
private static $classIdentifiers = [
|
||||
DocLexer::T_IDENTIFIER,
|
||||
DocLexer::T_TRUE,
|
||||
DocLexer::T_FALSE,
|
||||
DocLexer::T_NULL,
|
||||
];
|
||||
|
||||
/**
|
||||
* The lexer.
|
||||
*
|
||||
* @var DocLexer
|
||||
*/
|
||||
private $lexer;
|
||||
|
||||
/**
|
||||
* Current target context.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $target;
|
||||
|
||||
/**
|
||||
* Doc parser used to collect annotation target.
|
||||
*
|
||||
* @var DocParser
|
||||
*/
|
||||
private static $metadataParser;
|
||||
|
||||
/**
|
||||
* Flag to control if the current annotation is nested or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isNestedAnnotation = false;
|
||||
|
||||
/**
|
||||
* Hashmap containing all use-statements that are to be used when parsing
|
||||
* the given doc block.
|
||||
*
|
||||
* @var array<string, class-string>
|
||||
*/
|
||||
private $imports = [];
|
||||
|
||||
/**
|
||||
* This hashmap is used internally to cache results of class_exists()
|
||||
* look-ups.
|
||||
*
|
||||
* @var array<class-string, bool>
|
||||
*/
|
||||
private $classExists = [];
|
||||
|
||||
/**
|
||||
* Whether annotations that have not been imported should be ignored.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $ignoreNotImportedAnnotations = false;
|
||||
|
||||
/**
|
||||
* An array of default namespaces if operating in simple mode.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $namespaces = [];
|
||||
|
||||
/**
|
||||
* A list with annotations that are not causing exceptions when not resolved to an annotation class.
|
||||
*
|
||||
* The names must be the raw names as used in the class, not the fully qualified
|
||||
*
|
||||
* @var bool[] indexed by annotation name
|
||||
*/
|
||||
private $ignoredAnnotationNames = [];
|
||||
|
||||
/**
|
||||
* A list with annotations in namespaced format
|
||||
* that are not causing exceptions when not resolved to an annotation class.
|
||||
*
|
||||
* @var bool[] indexed by namespace name
|
||||
*/
|
||||
private $ignoredAnnotationNamespaces = [];
|
||||
|
||||
/** @var string */
|
||||
private $context = '';
|
||||
|
||||
/**
|
||||
* Hash-map for caching annotation metadata.
|
||||
*
|
||||
* @var array<class-string, mixed[]>
|
||||
*/
|
||||
private static $annotationMetadata = [
|
||||
Annotation\Target::class => [
|
||||
'is_annotation' => true,
|
||||
'has_constructor' => true,
|
||||
'has_named_argument_constructor' => false,
|
||||
'properties' => [],
|
||||
'targets_literal' => 'ANNOTATION_CLASS',
|
||||
'targets' => Target::TARGET_CLASS,
|
||||
'default_property' => 'value',
|
||||
'attribute_types' => [
|
||||
'value' => [
|
||||
'required' => false,
|
||||
'type' => 'array',
|
||||
'array_type' => 'string',
|
||||
'value' => 'array<string>',
|
||||
],
|
||||
],
|
||||
],
|
||||
Annotation\Attribute::class => [
|
||||
'is_annotation' => true,
|
||||
'has_constructor' => false,
|
||||
'has_named_argument_constructor' => false,
|
||||
'targets_literal' => 'ANNOTATION_ANNOTATION',
|
||||
'targets' => Target::TARGET_ANNOTATION,
|
||||
'default_property' => 'name',
|
||||
'properties' => [
|
||||
'name' => 'name',
|
||||
'type' => 'type',
|
||||
'required' => 'required',
|
||||
],
|
||||
'attribute_types' => [
|
||||
'value' => [
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'value' => 'string',
|
||||
],
|
||||
'type' => [
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'value' => 'string',
|
||||
],
|
||||
'required' => [
|
||||
'required' => false,
|
||||
'type' => 'boolean',
|
||||
'value' => 'boolean',
|
||||
],
|
||||
],
|
||||
],
|
||||
Annotation\Attributes::class => [
|
||||
'is_annotation' => true,
|
||||
'has_constructor' => false,
|
||||
'has_named_argument_constructor' => false,
|
||||
'targets_literal' => 'ANNOTATION_CLASS',
|
||||
'targets' => Target::TARGET_CLASS,
|
||||
'default_property' => 'value',
|
||||
'properties' => ['value' => 'value'],
|
||||
'attribute_types' => [
|
||||
'value' => [
|
||||
'type' => 'array',
|
||||
'required' => true,
|
||||
'array_type' => Annotation\Attribute::class,
|
||||
'value' => 'array<' . Annotation\Attribute::class . '>',
|
||||
],
|
||||
],
|
||||
],
|
||||
Annotation\Enum::class => [
|
||||
'is_annotation' => true,
|
||||
'has_constructor' => true,
|
||||
'has_named_argument_constructor' => false,
|
||||
'targets_literal' => 'ANNOTATION_PROPERTY',
|
||||
'targets' => Target::TARGET_PROPERTY,
|
||||
'default_property' => 'value',
|
||||
'properties' => ['value' => 'value'],
|
||||
'attribute_types' => [
|
||||
'value' => [
|
||||
'type' => 'array',
|
||||
'required' => true,
|
||||
],
|
||||
'literal' => [
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
Annotation\NamedArgumentConstructor::class => [
|
||||
'is_annotation' => true,
|
||||
'has_constructor' => false,
|
||||
'has_named_argument_constructor' => false,
|
||||
'targets_literal' => 'ANNOTATION_CLASS',
|
||||
'targets' => Target::TARGET_CLASS,
|
||||
'default_property' => null,
|
||||
'properties' => [],
|
||||
'attribute_types' => [],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Hash-map for handle types declaration.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private static $typeMap = [
|
||||
'float' => 'double',
|
||||
'bool' => 'boolean',
|
||||
// allow uppercase Boolean in honor of George Boole
|
||||
'Boolean' => 'boolean',
|
||||
'int' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructs a new DocParser.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->lexer = new DocLexer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the annotation names that are ignored during the parsing process.
|
||||
*
|
||||
* The names are supposed to be the raw names as used in the class, not the
|
||||
* fully qualified class names.
|
||||
*
|
||||
* @param bool[] $names indexed by annotation name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setIgnoredAnnotationNames(array $names)
|
||||
{
|
||||
$this->ignoredAnnotationNames = $names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the annotation namespaces that are ignored during the parsing process.
|
||||
*
|
||||
* @param bool[] $ignoredAnnotationNamespaces indexed by annotation namespace name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setIgnoredAnnotationNamespaces($ignoredAnnotationNamespaces)
|
||||
{
|
||||
$this->ignoredAnnotationNamespaces = $ignoredAnnotationNamespaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ignore on not-imported annotations.
|
||||
*
|
||||
* @param bool $bool
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setIgnoreNotImportedAnnotations($bool)
|
||||
{
|
||||
$this->ignoreNotImportedAnnotations = (bool) $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default namespaces.
|
||||
*
|
||||
* @param string $namespace
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function addNamespace($namespace)
|
||||
{
|
||||
if ($this->imports) {
|
||||
throw new RuntimeException('You must either use addNamespace(), or setImports(), but not both.');
|
||||
}
|
||||
|
||||
$this->namespaces[] = $namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the imports.
|
||||
*
|
||||
* @param array<string, class-string> $imports
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function setImports(array $imports)
|
||||
{
|
||||
if ($this->namespaces) {
|
||||
throw new RuntimeException('You must either use addNamespace(), or setImports(), but not both.');
|
||||
}
|
||||
|
||||
$this->imports = $imports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current target context as bitmask.
|
||||
*
|
||||
* @param int $target
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setTarget($target)
|
||||
{
|
||||
$this->target = $target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given docblock string for annotations.
|
||||
*
|
||||
* @param string $input The docblock string to parse.
|
||||
* @param string $context The parsing context.
|
||||
*
|
||||
* @phpstan-return list<object> Array of annotations. If no annotations are found, an empty array is returned.
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function parse($input, $context = '')
|
||||
{
|
||||
$pos = $this->findInitialTokenPosition($input);
|
||||
if ($pos === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->context = $context;
|
||||
|
||||
$this->lexer->setInput(trim(substr($input, $pos), '* /'));
|
||||
$this->lexer->moveNext();
|
||||
|
||||
return $this->Annotations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the first valid annotation
|
||||
*
|
||||
* @param string $input The docblock string to parse
|
||||
*/
|
||||
private function findInitialTokenPosition($input): ?int
|
||||
{
|
||||
$pos = 0;
|
||||
|
||||
// search for first valid annotation
|
||||
while (($pos = strpos($input, '@', $pos)) !== false) {
|
||||
$preceding = substr($input, $pos - 1, 1);
|
||||
|
||||
// if the @ is preceded by a space, a tab or * it is valid
|
||||
if ($pos === 0 || $preceding === ' ' || $preceding === '*' || $preceding === "\t") {
|
||||
return $pos;
|
||||
}
|
||||
|
||||
$pos++;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to match the given token with the current lookahead token.
|
||||
* If they match, updates the lookahead token; otherwise raises a syntax error.
|
||||
*
|
||||
* @param int $token Type of token.
|
||||
*
|
||||
* @return bool True if tokens match; false otherwise.
|
||||
*
|
||||
* @throws AnnotationException
|
||||
*/
|
||||
private function match(int $token): bool
|
||||
{
|
||||
if (! $this->lexer->isNextToken($token)) {
|
||||
throw $this->syntaxError($this->lexer->getLiteral($token));
|
||||
}
|
||||
|
||||
return $this->lexer->moveNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to match the current lookahead token with any of the given tokens.
|
||||
*
|
||||
* If any of them matches, this method updates the lookahead token; otherwise
|
||||
* a syntax error is raised.
|
||||
*
|
||||
* @phpstan-param list<mixed[]> $tokens
|
||||
*
|
||||
* @throws AnnotationException
|
||||
*/
|
||||
private function matchAny(array $tokens): bool
|
||||
{
|
||||
if (! $this->lexer->isNextTokenAny($tokens)) {
|
||||
throw $this->syntaxError(implode(' or ', array_map([$this->lexer, 'getLiteral'], $tokens)));
|
||||
}
|
||||
|
||||
return $this->lexer->moveNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new syntax error.
|
||||
*
|
||||
* @param string $expected Expected string.
|
||||
* @param mixed[]|null $token Optional token.
|
||||
*/
|
||||
private function syntaxError(string $expected, ?array $token = null): AnnotationException
|
||||
{
|
||||
if ($token === null) {
|
||||
$token = $this->lexer->lookahead;
|
||||
}
|
||||
|
||||
$message = sprintf('Expected %s, got ', $expected);
|
||||
$message .= $this->lexer->lookahead === null
|
||||
? 'end of string'
|
||||
: sprintf("'%s' at position %s", $token['value'], $token['position']);
|
||||
|
||||
if (strlen($this->context)) {
|
||||
$message .= ' in ' . $this->context;
|
||||
}
|
||||
|
||||
$message .= '.';
|
||||
|
||||
return AnnotationException::syntaxError($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to check if a class exists or not. This never goes through the PHP autoloading mechanism
|
||||
* but uses the {@link AnnotationRegistry} to load classes.
|
||||
*
|
||||
* @param class-string $fqcn
|
||||
*/
|
||||
private function classExists(string $fqcn): bool
|
||||
{
|
||||
if (isset($this->classExists[$fqcn])) {
|
||||
return $this->classExists[$fqcn];
|
||||
}
|
||||
|
||||
// first check if the class already exists, maybe loaded through another AnnotationReader
|
||||
if (class_exists($fqcn, false)) {
|
||||
return $this->classExists[$fqcn] = true;
|
||||
}
|
||||
|
||||
// final check, does this class exist?
|
||||
return $this->classExists[$fqcn] = AnnotationRegistry::loadAnnotationClass($fqcn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects parsing metadata for a given annotation class
|
||||
*
|
||||
* @param class-string $name The annotation name
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function collectAnnotationMetadata(string $name): void
|
||||
{
|
||||
if (self::$metadataParser === null) {
|
||||
self::$metadataParser = new self();
|
||||
|
||||
self::$metadataParser->setIgnoreNotImportedAnnotations(true);
|
||||
self::$metadataParser->setIgnoredAnnotationNames($this->ignoredAnnotationNames);
|
||||
self::$metadataParser->setImports([
|
||||
'enum' => Enum::class,
|
||||
'target' => Target::class,
|
||||
'attribute' => Attribute::class,
|
||||
'attributes' => Attributes::class,
|
||||
'namedargumentconstructor' => NamedArgumentConstructor::class,
|
||||
]);
|
||||
|
||||
// Make sure that annotations from metadata are loaded
|
||||
class_exists(Enum::class);
|
||||
class_exists(Target::class);
|
||||
class_exists(Attribute::class);
|
||||
class_exists(Attributes::class);
|
||||
class_exists(NamedArgumentConstructor::class);
|
||||
}
|
||||
|
||||
$class = new ReflectionClass($name);
|
||||
$docComment = $class->getDocComment();
|
||||
|
||||
// Sets default values for annotation metadata
|
||||
$constructor = $class->getConstructor();
|
||||
$metadata = [
|
||||
'default_property' => null,
|
||||
'has_constructor' => $constructor !== null && $constructor->getNumberOfParameters() > 0,
|
||||
'constructor_args' => [],
|
||||
'properties' => [],
|
||||
'property_types' => [],
|
||||
'attribute_types' => [],
|
||||
'targets_literal' => null,
|
||||
'targets' => Target::TARGET_ALL,
|
||||
'is_annotation' => strpos($docComment, '@Annotation') !== false,
|
||||
];
|
||||
|
||||
$metadata['has_named_argument_constructor'] = $metadata['has_constructor']
|
||||
&& $class->implementsInterface(NamedArgumentConstructorAnnotation::class);
|
||||
|
||||
// verify that the class is really meant to be an annotation
|
||||
if ($metadata['is_annotation']) {
|
||||
self::$metadataParser->setTarget(Target::TARGET_CLASS);
|
||||
|
||||
foreach (self::$metadataParser->parse($docComment, 'class @' . $name) as $annotation) {
|
||||
if ($annotation instanceof Target) {
|
||||
$metadata['targets'] = $annotation->targets;
|
||||
$metadata['targets_literal'] = $annotation->literal;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($annotation instanceof NamedArgumentConstructor) {
|
||||
$metadata['has_named_argument_constructor'] = $metadata['has_constructor'];
|
||||
if ($metadata['has_named_argument_constructor']) {
|
||||
// choose the first argument as the default property
|
||||
$metadata['default_property'] = $constructor->getParameters()[0]->getName();
|
||||
}
|
||||
}
|
||||
|
||||
if (! ($annotation instanceof Attributes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($annotation->value as $attribute) {
|
||||
$this->collectAttributeTypeMetadata($metadata, $attribute);
|
||||
}
|
||||
}
|
||||
|
||||
// if not has a constructor will inject values into public properties
|
||||
if ($metadata['has_constructor'] === false) {
|
||||
// collect all public properties
|
||||
foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
|
||||
$metadata['properties'][$property->name] = $property->name;
|
||||
|
||||
$propertyComment = $property->getDocComment();
|
||||
if ($propertyComment === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attribute = new Attribute();
|
||||
|
||||
$attribute->required = (strpos($propertyComment, '@Required') !== false);
|
||||
$attribute->name = $property->name;
|
||||
$attribute->type = (strpos($propertyComment, '@var') !== false &&
|
||||
preg_match('/@var\s+([^\s]+)/', $propertyComment, $matches))
|
||||
? $matches[1]
|
||||
: 'mixed';
|
||||
|
||||
$this->collectAttributeTypeMetadata($metadata, $attribute);
|
||||
|
||||
// checks if the property has @Enum
|
||||
if (strpos($propertyComment, '@Enum') === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$context = 'property ' . $class->name . '::$' . $property->name;
|
||||
|
||||
self::$metadataParser->setTarget(Target::TARGET_PROPERTY);
|
||||
|
||||
foreach (self::$metadataParser->parse($propertyComment, $context) as $annotation) {
|
||||
if (! $annotation instanceof Enum) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$metadata['enum'][$property->name]['value'] = $annotation->value;
|
||||
$metadata['enum'][$property->name]['literal'] = (! empty($annotation->literal))
|
||||
? $annotation->literal
|
||||
: $annotation->value;
|
||||
}
|
||||
}
|
||||
|
||||
// choose the first property as default property
|
||||
$metadata['default_property'] = reset($metadata['properties']);
|
||||
} elseif ($metadata['has_named_argument_constructor']) {
|
||||
foreach ($constructor->getParameters() as $parameter) {
|
||||
$metadata['constructor_args'][$parameter->getName()] = [
|
||||
'position' => $parameter->getPosition(),
|
||||
'default' => $parameter->isOptional() ? $parameter->getDefaultValue() : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self::$annotationMetadata[$name] = $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects parsing metadata for a given attribute.
|
||||
*
|
||||
* @param mixed[] $metadata
|
||||
*/
|
||||
private function collectAttributeTypeMetadata(array &$metadata, Attribute $attribute): void
|
||||
{
|
||||
// handle internal type declaration
|
||||
$type = self::$typeMap[$attribute->type] ?? $attribute->type;
|
||||
|
||||
// handle the case if the property type is mixed
|
||||
if ($type === 'mixed') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Evaluate type
|
||||
$pos = strpos($type, '<');
|
||||
if ($pos !== false) {
|
||||
// Checks if the property has array<type>
|
||||
$arrayType = substr($type, $pos + 1, -1);
|
||||
$type = 'array';
|
||||
|
||||
if (isset(self::$typeMap[$arrayType])) {
|
||||
$arrayType = self::$typeMap[$arrayType];
|
||||
}
|
||||
|
||||
$metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType;
|
||||
} else {
|
||||
// Checks if the property has type[]
|
||||
$pos = strrpos($type, '[');
|
||||
if ($pos !== false) {
|
||||
$arrayType = substr($type, 0, $pos);
|
||||
$type = 'array';
|
||||
|
||||
if (isset(self::$typeMap[$arrayType])) {
|
||||
$arrayType = self::$typeMap[$arrayType];
|
||||
}
|
||||
|
||||
$metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType;
|
||||
}
|
||||
}
|
||||
|
||||
$metadata['attribute_types'][$attribute->name]['type'] = $type;
|
||||
$metadata['attribute_types'][$attribute->name]['value'] = $attribute->type;
|
||||
$metadata['attribute_types'][$attribute->name]['required'] = $attribute->required;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotations ::= Annotation {[ "*" ]* [Annotation]}*
|
||||
*
|
||||
* @phpstan-return list<object>
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function Annotations(): array
|
||||
{
|
||||
$annotations = [];
|
||||
|
||||
while ($this->lexer->lookahead !== null) {
|
||||
if ($this->lexer->lookahead['type'] !== DocLexer::T_AT) {
|
||||
$this->lexer->moveNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
// make sure the @ is preceded by non-catchable pattern
|
||||
if (
|
||||
$this->lexer->token !== null &&
|
||||
$this->lexer->lookahead['position'] === $this->lexer->token['position'] + strlen(
|
||||
$this->lexer->token['value']
|
||||
)
|
||||
) {
|
||||
$this->lexer->moveNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
// make sure the @ is followed by either a namespace separator, or
|
||||
// an identifier token
|
||||
$peek = $this->lexer->glimpse();
|
||||
if (
|
||||
($peek === null)
|
||||
|| ($peek['type'] !== DocLexer::T_NAMESPACE_SEPARATOR && ! in_array(
|
||||
$peek['type'],
|
||||
self::$classIdentifiers,
|
||||
true
|
||||
))
|
||||
|| $peek['position'] !== $this->lexer->lookahead['position'] + 1
|
||||
) {
|
||||
$this->lexer->moveNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->isNestedAnnotation = false;
|
||||
$annot = $this->Annotation();
|
||||
if ($annot === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$annotations[] = $annot;
|
||||
}
|
||||
|
||||
return $annotations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotation ::= "@" AnnotationName MethodCall
|
||||
* AnnotationName ::= QualifiedName | SimpleName
|
||||
* QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName
|
||||
* NameSpacePart ::= identifier | null | false | true
|
||||
* SimpleName ::= identifier | null | false | true
|
||||
*
|
||||
* @return object|false False if it is not a valid annotation.
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function Annotation()
|
||||
{
|
||||
$this->match(DocLexer::T_AT);
|
||||
|
||||
// check if we have an annotation
|
||||
$name = $this->Identifier();
|
||||
|
||||
if (
|
||||
$this->lexer->isNextToken(DocLexer::T_MINUS)
|
||||
&& $this->lexer->nextTokenIsAdjacent()
|
||||
) {
|
||||
// Annotations with dashes, such as "@foo-" or "@foo-bar", are to be discarded
|
||||
return false;
|
||||
}
|
||||
|
||||
// only process names which are not fully qualified, yet
|
||||
// fully qualified names must start with a \
|
||||
$originalName = $name;
|
||||
|
||||
if ($name[0] !== '\\') {
|
||||
$pos = strpos($name, '\\');
|
||||
$alias = ($pos === false) ? $name : substr($name, 0, $pos);
|
||||
$found = false;
|
||||
$loweredAlias = strtolower($alias);
|
||||
|
||||
if ($this->namespaces) {
|
||||
foreach ($this->namespaces as $namespace) {
|
||||
if ($this->classExists($namespace . '\\' . $name)) {
|
||||
$name = $namespace . '\\' . $name;
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} elseif (isset($this->imports[$loweredAlias])) {
|
||||
$namespace = ltrim($this->imports[$loweredAlias], '\\');
|
||||
$name = ($pos !== false)
|
||||
? $namespace . substr($name, $pos)
|
||||
: $namespace;
|
||||
$found = $this->classExists($name);
|
||||
} elseif (
|
||||
! isset($this->ignoredAnnotationNames[$name])
|
||||
&& isset($this->imports['__NAMESPACE__'])
|
||||
&& $this->classExists($this->imports['__NAMESPACE__'] . '\\' . $name)
|
||||
) {
|
||||
$name = $this->imports['__NAMESPACE__'] . '\\' . $name;
|
||||
$found = true;
|
||||
} elseif (! isset($this->ignoredAnnotationNames[$name]) && $this->classExists($name)) {
|
||||
$found = true;
|
||||
}
|
||||
|
||||
if (! $found) {
|
||||
if ($this->isIgnoredAnnotation($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw AnnotationException::semanticalError(sprintf(
|
||||
<<<'EXCEPTION'
|
||||
The annotation "@%s" in %s was never imported. Did you maybe forget to add a "use" statement for this annotation?
|
||||
EXCEPTION
|
||||
,
|
||||
$name,
|
||||
$this->context
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$name = ltrim($name, '\\');
|
||||
|
||||
if (! $this->classExists($name)) {
|
||||
throw AnnotationException::semanticalError(sprintf(
|
||||
'The annotation "@%s" in %s does not exist, or could not be auto-loaded.',
|
||||
$name,
|
||||
$this->context
|
||||
));
|
||||
}
|
||||
|
||||
// at this point, $name contains the fully qualified class name of the
|
||||
// annotation, and it is also guaranteed that this class exists, and
|
||||
// that it is loaded
|
||||
|
||||
// collects the metadata annotation only if there is not yet
|
||||
if (! isset(self::$annotationMetadata[$name])) {
|
||||
$this->collectAnnotationMetadata($name);
|
||||
}
|
||||
|
||||
// verify that the class is really meant to be an annotation and not just any ordinary class
|
||||
if (self::$annotationMetadata[$name]['is_annotation'] === false) {
|
||||
if ($this->isIgnoredAnnotation($originalName) || $this->isIgnoredAnnotation($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw AnnotationException::semanticalError(sprintf(
|
||||
<<<'EXCEPTION'
|
||||
The class "%s" is not annotated with @Annotation.
|
||||
Are you sure this class can be used as annotation?
|
||||
If so, then you need to add @Annotation to the _class_ doc comment of "%s".
|
||||
If it is indeed no annotation, then you need to add @IgnoreAnnotation("%s") to the _class_ doc comment of %s.
|
||||
EXCEPTION
|
||||
,
|
||||
$name,
|
||||
$name,
|
||||
$originalName,
|
||||
$this->context
|
||||
));
|
||||
}
|
||||
|
||||
//if target is nested annotation
|
||||
$target = $this->isNestedAnnotation ? Target::TARGET_ANNOTATION : $this->target;
|
||||
|
||||
// Next will be nested
|
||||
$this->isNestedAnnotation = true;
|
||||
|
||||
//if annotation does not support current target
|
||||
if ((self::$annotationMetadata[$name]['targets'] & $target) === 0 && $target) {
|
||||
throw AnnotationException::semanticalError(
|
||||
sprintf(
|
||||
<<<'EXCEPTION'
|
||||
Annotation @%s is not allowed to be declared on %s. You may only use this annotation on these code elements: %s.
|
||||
EXCEPTION
|
||||
,
|
||||
$originalName,
|
||||
$this->context,
|
||||
self::$annotationMetadata[$name]['targets_literal']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$arguments = $this->MethodCall();
|
||||
$values = $this->resolvePositionalValues($arguments, $name);
|
||||
|
||||
if (isset(self::$annotationMetadata[$name]['enum'])) {
|
||||
// checks all declared attributes
|
||||
foreach (self::$annotationMetadata[$name]['enum'] as $property => $enum) {
|
||||
// checks if the attribute is a valid enumerator
|
||||
if (isset($values[$property]) && ! in_array($values[$property], $enum['value'])) {
|
||||
throw AnnotationException::enumeratorError(
|
||||
$property,
|
||||
$name,
|
||||
$this->context,
|
||||
$enum['literal'],
|
||||
$values[$property]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// checks all declared attributes
|
||||
foreach (self::$annotationMetadata[$name]['attribute_types'] as $property => $type) {
|
||||
if (
|
||||
$property === self::$annotationMetadata[$name]['default_property']
|
||||
&& ! isset($values[$property]) && isset($values['value'])
|
||||
) {
|
||||
$property = 'value';
|
||||
}
|
||||
|
||||
// handle a not given attribute or null value
|
||||
if (! isset($values[$property])) {
|
||||
if ($type['required']) {
|
||||
throw AnnotationException::requiredError(
|
||||
$property,
|
||||
$originalName,
|
||||
$this->context,
|
||||
'a(n) ' . $type['value']
|
||||
);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($type['type'] === 'array') {
|
||||
// handle the case of a single value
|
||||
if (! is_array($values[$property])) {
|
||||
$values[$property] = [$values[$property]];
|
||||
}
|
||||
|
||||
// checks if the attribute has array type declaration, such as "array<string>"
|
||||
if (isset($type['array_type'])) {
|
||||
foreach ($values[$property] as $item) {
|
||||
if (gettype($item) !== $type['array_type'] && ! $item instanceof $type['array_type']) {
|
||||
throw AnnotationException::attributeTypeError(
|
||||
$property,
|
||||
$originalName,
|
||||
$this->context,
|
||||
'either a(n) ' . $type['array_type'] . ', or an array of ' . $type['array_type'] . 's',
|
||||
$item
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif (gettype($values[$property]) !== $type['type'] && ! $values[$property] instanceof $type['type']) {
|
||||
throw AnnotationException::attributeTypeError(
|
||||
$property,
|
||||
$originalName,
|
||||
$this->context,
|
||||
'a(n) ' . $type['value'],
|
||||
$values[$property]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (self::$annotationMetadata[$name]['has_named_argument_constructor']) {
|
||||
if (PHP_VERSION_ID >= 80000) {
|
||||
return $this->instantiateAnnotiation($originalName, $this->context, $name, $values);
|
||||
}
|
||||
|
||||
$positionalValues = [];
|
||||
foreach (self::$annotationMetadata[$name]['constructor_args'] as $property => $parameter) {
|
||||
$positionalValues[$parameter['position']] = $parameter['default'];
|
||||
}
|
||||
|
||||
foreach ($values as $property => $value) {
|
||||
if (! isset(self::$annotationMetadata[$name]['constructor_args'][$property])) {
|
||||
throw AnnotationException::creationError(sprintf(
|
||||
<<<'EXCEPTION'
|
||||
The annotation @%s declared on %s does not have a property named "%s"
|
||||
that can be set through its named arguments constructor.
|
||||
Available named arguments: %s
|
||||
EXCEPTION
|
||||
,
|
||||
$originalName,
|
||||
$this->context,
|
||||
$property,
|
||||
implode(', ', array_keys(self::$annotationMetadata[$name]['constructor_args']))
|
||||
));
|
||||
}
|
||||
|
||||
$positionalValues[self::$annotationMetadata[$name]['constructor_args'][$property]['position']] = $value;
|
||||
}
|
||||
|
||||
return $this->instantiateAnnotiation($originalName, $this->context, $name, $positionalValues);
|
||||
}
|
||||
|
||||
// check if the annotation expects values via the constructor,
|
||||
// or directly injected into public properties
|
||||
if (self::$annotationMetadata[$name]['has_constructor'] === true) {
|
||||
return $this->instantiateAnnotiation($originalName, $this->context, $name, [$values]);
|
||||
}
|
||||
|
||||
$instance = $this->instantiateAnnotiation($originalName, $this->context, $name, []);
|
||||
|
||||
foreach ($values as $property => $value) {
|
||||
if (! isset(self::$annotationMetadata[$name]['properties'][$property])) {
|
||||
if ($property !== 'value') {
|
||||
throw AnnotationException::creationError(sprintf(
|
||||
<<<'EXCEPTION'
|
||||
The annotation @%s declared on %s does not have a property named "%s".
|
||||
Available properties: %s
|
||||
EXCEPTION
|
||||
,
|
||||
$originalName,
|
||||
$this->context,
|
||||
$property,
|
||||
implode(', ', self::$annotationMetadata[$name]['properties'])
|
||||
));
|
||||
}
|
||||
|
||||
// handle the case if the property has no annotations
|
||||
$property = self::$annotationMetadata[$name]['default_property'];
|
||||
if (! $property) {
|
||||
throw AnnotationException::creationError(sprintf(
|
||||
'The annotation @%s declared on %s does not accept any values, but got %s.',
|
||||
$originalName,
|
||||
$this->context,
|
||||
json_encode($values)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$instance->{$property} = $value;
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* MethodCall ::= ["(" [Values] ")"]
|
||||
*
|
||||
* @return mixed[]
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function MethodCall(): array
|
||||
{
|
||||
$values = [];
|
||||
|
||||
if (! $this->lexer->isNextToken(DocLexer::T_OPEN_PARENTHESIS)) {
|
||||
return $values;
|
||||
}
|
||||
|
||||
$this->match(DocLexer::T_OPEN_PARENTHESIS);
|
||||
|
||||
if (! $this->lexer->isNextToken(DocLexer::T_CLOSE_PARENTHESIS)) {
|
||||
$values = $this->Values();
|
||||
}
|
||||
|
||||
$this->match(DocLexer::T_CLOSE_PARENTHESIS);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Values ::= Array | Value {"," Value}* [","]
|
||||
*
|
||||
* @return mixed[]
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function Values(): array
|
||||
{
|
||||
$values = [$this->Value()];
|
||||
|
||||
while ($this->lexer->isNextToken(DocLexer::T_COMMA)) {
|
||||
$this->match(DocLexer::T_COMMA);
|
||||
|
||||
if ($this->lexer->isNextToken(DocLexer::T_CLOSE_PARENTHESIS)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$token = $this->lexer->lookahead;
|
||||
$value = $this->Value();
|
||||
|
||||
$values[] = $value;
|
||||
}
|
||||
|
||||
$namedArguments = [];
|
||||
$positionalArguments = [];
|
||||
foreach ($values as $k => $value) {
|
||||
if (is_object($value) && $value instanceof stdClass) {
|
||||
$namedArguments[$value->name] = $value->value;
|
||||
} else {
|
||||
$positionalArguments[$k] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return ['named_arguments' => $namedArguments, 'positional_arguments' => $positionalArguments];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant ::= integer | string | float | boolean
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws AnnotationException
|
||||
*/
|
||||
private function Constant()
|
||||
{
|
||||
$identifier = $this->Identifier();
|
||||
|
||||
if (! defined($identifier) && strpos($identifier, '::') !== false && $identifier[0] !== '\\') {
|
||||
[$className, $const] = explode('::', $identifier);
|
||||
|
||||
$pos = strpos($className, '\\');
|
||||
$alias = ($pos === false) ? $className : substr($className, 0, $pos);
|
||||
$found = false;
|
||||
$loweredAlias = strtolower($alias);
|
||||
|
||||
switch (true) {
|
||||
case ! empty($this->namespaces):
|
||||
foreach ($this->namespaces as $ns) {
|
||||
if (class_exists($ns . '\\' . $className) || interface_exists($ns . '\\' . $className)) {
|
||||
$className = $ns . '\\' . $className;
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case isset($this->imports[$loweredAlias]):
|
||||
$found = true;
|
||||
$className = ($pos !== false)
|
||||
? $this->imports[$loweredAlias] . substr($className, $pos)
|
||||
: $this->imports[$loweredAlias];
|
||||
break;
|
||||
|
||||
default:
|
||||
if (isset($this->imports['__NAMESPACE__'])) {
|
||||
$ns = $this->imports['__NAMESPACE__'];
|
||||
|
||||
if (class_exists($ns . '\\' . $className) || interface_exists($ns . '\\' . $className)) {
|
||||
$className = $ns . '\\' . $className;
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
$identifier = $className . '::' . $const;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if identifier ends with ::class and remove the leading backslash if it exists.
|
||||
*/
|
||||
if (
|
||||
$this->identifierEndsWithClassConstant($identifier) &&
|
||||
! $this->identifierStartsWithBackslash($identifier)
|
||||
) {
|
||||
return substr($identifier, 0, $this->getClassConstantPositionInIdentifier($identifier));
|
||||
}
|
||||
|
||||
if ($this->identifierEndsWithClassConstant($identifier) && $this->identifierStartsWithBackslash($identifier)) {
|
||||
return substr($identifier, 1, $this->getClassConstantPositionInIdentifier($identifier) - 1);
|
||||
}
|
||||
|
||||
if (! defined($identifier)) {
|
||||
throw AnnotationException::semanticalErrorConstants($identifier, $this->context);
|
||||
}
|
||||
|
||||
return constant($identifier);
|
||||
}
|
||||
|
||||
private function identifierStartsWithBackslash(string $identifier): bool
|
||||
{
|
||||
return $identifier[0] === '\\';
|
||||
}
|
||||
|
||||
private function identifierEndsWithClassConstant(string $identifier): bool
|
||||
{
|
||||
return $this->getClassConstantPositionInIdentifier($identifier) === strlen($identifier) - strlen('::class');
|
||||
}
|
||||
|
||||
/** @return int|false */
|
||||
private function getClassConstantPositionInIdentifier(string $identifier)
|
||||
{
|
||||
return stripos($identifier, '::class');
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifier ::= string
|
||||
*
|
||||
* @throws AnnotationException
|
||||
*/
|
||||
private function Identifier(): string
|
||||
{
|
||||
// check if we have an annotation
|
||||
if (! $this->lexer->isNextTokenAny(self::$classIdentifiers)) {
|
||||
throw $this->syntaxError('namespace separator or identifier');
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
$className = $this->lexer->token['value'];
|
||||
|
||||
while (
|
||||
$this->lexer->lookahead !== null &&
|
||||
$this->lexer->lookahead['position'] === ($this->lexer->token['position'] +
|
||||
strlen($this->lexer->token['value'])) &&
|
||||
$this->lexer->isNextToken(DocLexer::T_NAMESPACE_SEPARATOR)
|
||||
) {
|
||||
$this->match(DocLexer::T_NAMESPACE_SEPARATOR);
|
||||
$this->matchAny(self::$classIdentifiers);
|
||||
|
||||
$className .= '\\' . $this->lexer->token['value'];
|
||||
}
|
||||
|
||||
return $className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value ::= PlainValue | FieldAssignment
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function Value()
|
||||
{
|
||||
$peek = $this->lexer->glimpse();
|
||||
|
||||
if ($peek['type'] === DocLexer::T_EQUALS) {
|
||||
return $this->FieldAssignment();
|
||||
}
|
||||
|
||||
return $this->PlainValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* PlainValue ::= integer | string | float | boolean | Array | Annotation
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function PlainValue()
|
||||
{
|
||||
if ($this->lexer->isNextToken(DocLexer::T_OPEN_CURLY_BRACES)) {
|
||||
return $this->Arrayx();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(DocLexer::T_AT)) {
|
||||
return $this->Annotation();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(DocLexer::T_IDENTIFIER)) {
|
||||
return $this->Constant();
|
||||
}
|
||||
|
||||
switch ($this->lexer->lookahead['type']) {
|
||||
case DocLexer::T_STRING:
|
||||
$this->match(DocLexer::T_STRING);
|
||||
|
||||
return $this->lexer->token['value'];
|
||||
|
||||
case DocLexer::T_INTEGER:
|
||||
$this->match(DocLexer::T_INTEGER);
|
||||
|
||||
return (int) $this->lexer->token['value'];
|
||||
|
||||
case DocLexer::T_FLOAT:
|
||||
$this->match(DocLexer::T_FLOAT);
|
||||
|
||||
return (float) $this->lexer->token['value'];
|
||||
|
||||
case DocLexer::T_TRUE:
|
||||
$this->match(DocLexer::T_TRUE);
|
||||
|
||||
return true;
|
||||
|
||||
case DocLexer::T_FALSE:
|
||||
$this->match(DocLexer::T_FALSE);
|
||||
|
||||
return false;
|
||||
|
||||
case DocLexer::T_NULL:
|
||||
$this->match(DocLexer::T_NULL);
|
||||
|
||||
return null;
|
||||
|
||||
default:
|
||||
throw $this->syntaxError('PlainValue');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FieldAssignment ::= FieldName "=" PlainValue
|
||||
* FieldName ::= identifier
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function FieldAssignment(): stdClass
|
||||
{
|
||||
$this->match(DocLexer::T_IDENTIFIER);
|
||||
$fieldName = $this->lexer->token['value'];
|
||||
|
||||
$this->match(DocLexer::T_EQUALS);
|
||||
|
||||
$item = new stdClass();
|
||||
$item->name = $fieldName;
|
||||
$item->value = $this->PlainValue();
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array ::= "{" ArrayEntry {"," ArrayEntry}* [","] "}"
|
||||
*
|
||||
* @return mixed[]
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function Arrayx(): array
|
||||
{
|
||||
$array = $values = [];
|
||||
|
||||
$this->match(DocLexer::T_OPEN_CURLY_BRACES);
|
||||
|
||||
// If the array is empty, stop parsing and return.
|
||||
if ($this->lexer->isNextToken(DocLexer::T_CLOSE_CURLY_BRACES)) {
|
||||
$this->match(DocLexer::T_CLOSE_CURLY_BRACES);
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
$values[] = $this->ArrayEntry();
|
||||
|
||||
while ($this->lexer->isNextToken(DocLexer::T_COMMA)) {
|
||||
$this->match(DocLexer::T_COMMA);
|
||||
|
||||
// optional trailing comma
|
||||
if ($this->lexer->isNextToken(DocLexer::T_CLOSE_CURLY_BRACES)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$values[] = $this->ArrayEntry();
|
||||
}
|
||||
|
||||
$this->match(DocLexer::T_CLOSE_CURLY_BRACES);
|
||||
|
||||
foreach ($values as $value) {
|
||||
[$key, $val] = $value;
|
||||
|
||||
if ($key !== null) {
|
||||
$array[$key] = $val;
|
||||
} else {
|
||||
$array[] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* ArrayEntry ::= Value | KeyValuePair
|
||||
* KeyValuePair ::= Key ("=" | ":") PlainValue | Constant
|
||||
* Key ::= string | integer | Constant
|
||||
*
|
||||
* @phpstan-return array{mixed, mixed}
|
||||
*
|
||||
* @throws AnnotationException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function ArrayEntry(): array
|
||||
{
|
||||
$peek = $this->lexer->glimpse();
|
||||
|
||||
if (
|
||||
$peek['type'] === DocLexer::T_EQUALS
|
||||
|| $peek['type'] === DocLexer::T_COLON
|
||||
) {
|
||||
if ($this->lexer->isNextToken(DocLexer::T_IDENTIFIER)) {
|
||||
$key = $this->Constant();
|
||||
} else {
|
||||
$this->matchAny([DocLexer::T_INTEGER, DocLexer::T_STRING]);
|
||||
$key = $this->lexer->token['value'];
|
||||
}
|
||||
|
||||
$this->matchAny([DocLexer::T_EQUALS, DocLexer::T_COLON]);
|
||||
|
||||
return [$key, $this->PlainValue()];
|
||||
}
|
||||
|
||||
return [null, $this->Value()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given $name matches any ignored annotation name or namespace
|
||||
*/
|
||||
private function isIgnoredAnnotation(string $name): bool
|
||||
{
|
||||
if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$name])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (array_keys($this->ignoredAnnotationNamespaces) as $ignoredAnnotationNamespace) {
|
||||
$ignoredAnnotationNamespace = rtrim($ignoredAnnotationNamespace, '\\') . '\\';
|
||||
|
||||
if (stripos(rtrim($name, '\\') . '\\', $ignoredAnnotationNamespace) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve positional arguments (without name) to named ones
|
||||
*
|
||||
* @param array<string,mixed> $arguments
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function resolvePositionalValues(array $arguments, string $name): array
|
||||
{
|
||||
$positionalArguments = $arguments['positional_arguments'] ?? [];
|
||||
$values = $arguments['named_arguments'] ?? [];
|
||||
|
||||
if (
|
||||
self::$annotationMetadata[$name]['has_named_argument_constructor']
|
||||
&& self::$annotationMetadata[$name]['default_property'] !== null
|
||||
) {
|
||||
// We must ensure that we don't have positional arguments after named ones
|
||||
$positions = array_keys($positionalArguments);
|
||||
$lastPosition = null;
|
||||
foreach ($positions as $position) {
|
||||
if (
|
||||
($lastPosition === null && $position !== 0) ||
|
||||
($lastPosition !== null && $position !== $lastPosition + 1)
|
||||
) {
|
||||
throw $this->syntaxError('Positional arguments after named arguments is not allowed');
|
||||
}
|
||||
|
||||
$lastPosition = $position;
|
||||
}
|
||||
|
||||
foreach (self::$annotationMetadata[$name]['constructor_args'] as $property => $parameter) {
|
||||
$position = $parameter['position'];
|
||||
if (isset($values[$property]) || ! isset($positionalArguments[$position])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$values[$property] = $positionalArguments[$position];
|
||||
}
|
||||
} else {
|
||||
if (count($positionalArguments) > 0 && ! isset($values['value'])) {
|
||||
if (count($positionalArguments) === 1) {
|
||||
$value = array_pop($positionalArguments);
|
||||
} else {
|
||||
$value = array_values($positionalArguments);
|
||||
}
|
||||
|
||||
$values['value'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to instantiate the annotation and catch and process any exceptions related to failure
|
||||
*
|
||||
* @param class-string $name
|
||||
* @param array<string,mixed> $arguments
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @throws AnnotationException
|
||||
*/
|
||||
private function instantiateAnnotiation(string $originalName, string $context, string $name, array $arguments)
|
||||
{
|
||||
try {
|
||||
return new $name(...$arguments);
|
||||
} catch (Throwable $exception) {
|
||||
throw AnnotationException::creationError(
|
||||
sprintf(
|
||||
'An error occurred while instantiating the annotation @%s declared on %s: "%s".',
|
||||
$originalName,
|
||||
$context,
|
||||
$exception->getMessage()
|
||||
),
|
||||
$exception
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
315
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/FileCacheReader.php
vendored
Normal file
315
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/FileCacheReader.php
vendored
Normal file
@ -0,0 +1,315 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
use RuntimeException;
|
||||
|
||||
use function chmod;
|
||||
use function file_put_contents;
|
||||
use function filemtime;
|
||||
use function gettype;
|
||||
use function is_dir;
|
||||
use function is_file;
|
||||
use function is_int;
|
||||
use function is_writable;
|
||||
use function mkdir;
|
||||
use function rename;
|
||||
use function rtrim;
|
||||
use function serialize;
|
||||
use function sha1;
|
||||
use function sprintf;
|
||||
use function strtr;
|
||||
use function tempnam;
|
||||
use function uniqid;
|
||||
use function unlink;
|
||||
use function var_export;
|
||||
|
||||
/**
|
||||
* File cache reader for annotations.
|
||||
*
|
||||
* @deprecated the FileCacheReader is deprecated and will be removed
|
||||
* in version 2.0.0 of doctrine/annotations. Please use the
|
||||
* {@see \Doctrine\Common\Annotations\PsrCachedReader} instead.
|
||||
*/
|
||||
class FileCacheReader implements Reader
|
||||
{
|
||||
/** @var Reader */
|
||||
private $reader;
|
||||
|
||||
/** @var string */
|
||||
private $dir;
|
||||
|
||||
/** @var bool */
|
||||
private $debug;
|
||||
|
||||
/** @phpstan-var array<string, list<object>> */
|
||||
private $loadedAnnotations = [];
|
||||
|
||||
/** @var array<string, string> */
|
||||
private $classNameHashes = [];
|
||||
|
||||
/** @var int */
|
||||
private $umask;
|
||||
|
||||
/**
|
||||
* @param string $cacheDir
|
||||
* @param bool $debug
|
||||
* @param int $umask
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(Reader $reader, $cacheDir, $debug = false, $umask = 0002)
|
||||
{
|
||||
if (! is_int($umask)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'The parameter umask must be an integer, was: %s',
|
||||
gettype($umask)
|
||||
));
|
||||
}
|
||||
|
||||
$this->reader = $reader;
|
||||
$this->umask = $umask;
|
||||
|
||||
if (! is_dir($cacheDir) && ! @mkdir($cacheDir, 0777 & (~$this->umask), true)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'The directory "%s" does not exist and could not be created.',
|
||||
$cacheDir
|
||||
));
|
||||
}
|
||||
|
||||
$this->dir = rtrim($cacheDir, '\\/');
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(ReflectionClass $class)
|
||||
{
|
||||
if (! isset($this->classNameHashes[$class->name])) {
|
||||
$this->classNameHashes[$class->name] = sha1($class->name);
|
||||
}
|
||||
|
||||
$key = $this->classNameHashes[$class->name];
|
||||
|
||||
if (isset($this->loadedAnnotations[$key])) {
|
||||
return $this->loadedAnnotations[$key];
|
||||
}
|
||||
|
||||
$path = $this->dir . '/' . strtr($key, '\\', '-') . '.cache.php';
|
||||
if (! is_file($path)) {
|
||||
$annot = $this->reader->getClassAnnotations($class);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
$filename = $class->getFilename();
|
||||
if (
|
||||
$this->debug
|
||||
&& $filename !== false
|
||||
&& filemtime($path) < filemtime($filename)
|
||||
) {
|
||||
@unlink($path);
|
||||
|
||||
$annot = $this->reader->getClassAnnotations($class);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$key] = include $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
if (! isset($this->classNameHashes[$class->name])) {
|
||||
$this->classNameHashes[$class->name] = sha1($class->name);
|
||||
}
|
||||
|
||||
$key = $this->classNameHashes[$class->name] . '$' . $property->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$key])) {
|
||||
return $this->loadedAnnotations[$key];
|
||||
}
|
||||
|
||||
$path = $this->dir . '/' . strtr($key, '\\', '-') . '.cache.php';
|
||||
if (! is_file($path)) {
|
||||
$annot = $this->reader->getPropertyAnnotations($property);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
$filename = $class->getFilename();
|
||||
if (
|
||||
$this->debug
|
||||
&& $filename !== false
|
||||
&& filemtime($path) < filemtime($filename)
|
||||
) {
|
||||
@unlink($path);
|
||||
|
||||
$annot = $this->reader->getPropertyAnnotations($property);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$key] = include $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
if (! isset($this->classNameHashes[$class->name])) {
|
||||
$this->classNameHashes[$class->name] = sha1($class->name);
|
||||
}
|
||||
|
||||
$key = $this->classNameHashes[$class->name] . '#' . $method->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$key])) {
|
||||
return $this->loadedAnnotations[$key];
|
||||
}
|
||||
|
||||
$path = $this->dir . '/' . strtr($key, '\\', '-') . '.cache.php';
|
||||
if (! is_file($path)) {
|
||||
$annot = $this->reader->getMethodAnnotations($method);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
$filename = $class->getFilename();
|
||||
if (
|
||||
$this->debug
|
||||
&& $filename !== false
|
||||
&& filemtime($path) < filemtime($filename)
|
||||
) {
|
||||
@unlink($path);
|
||||
|
||||
$annot = $this->reader->getMethodAnnotations($method);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$key] = include $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the cache file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function saveCacheFile($path, $data)
|
||||
{
|
||||
if (! is_writable($this->dir)) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
<<<'EXCEPTION'
|
||||
The directory "%s" is not writable. Both the webserver and the console user need access.
|
||||
You can manage access rights for multiple users with "chmod +a".
|
||||
If your system does not support this, check out the acl package.,
|
||||
EXCEPTION
|
||||
,
|
||||
$this->dir
|
||||
));
|
||||
}
|
||||
|
||||
$tempfile = tempnam($this->dir, uniqid('', true));
|
||||
|
||||
if ($tempfile === false) {
|
||||
throw new RuntimeException(sprintf('Unable to create tempfile in directory: %s', $this->dir));
|
||||
}
|
||||
|
||||
@chmod($tempfile, 0666 & (~$this->umask));
|
||||
|
||||
$written = file_put_contents(
|
||||
$tempfile,
|
||||
'<?php return unserialize(' . var_export(serialize($data), true) . ');'
|
||||
);
|
||||
|
||||
if ($written === false) {
|
||||
throw new RuntimeException(sprintf('Unable to write cached file to: %s', $tempfile));
|
||||
}
|
||||
|
||||
@chmod($tempfile, 0666 & (~$this->umask));
|
||||
|
||||
if (rename($tempfile, $path) === false) {
|
||||
@unlink($tempfile);
|
||||
|
||||
throw new RuntimeException(sprintf('Unable to rename %s to %s', $tempfile, $path));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(ReflectionClass $class, $annotationName)
|
||||
{
|
||||
$annotations = $this->getClassAnnotations($class);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
$annotations = $this->getMethodAnnotations($method);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
$annotations = $this->getPropertyAnnotations($property);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears loaded annotations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearLoadedAnnotations()
|
||||
{
|
||||
$this->loadedAnnotations = [];
|
||||
}
|
||||
}
|
178
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/ImplicitlyIgnoredAnnotationNames.php
vendored
Normal file
178
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/ImplicitlyIgnoredAnnotationNames.php
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* A list of annotations that are implicitly ignored during the parsing process.
|
||||
*
|
||||
* All names are case sensitive.
|
||||
*/
|
||||
final class ImplicitlyIgnoredAnnotationNames
|
||||
{
|
||||
private const Reserved = [
|
||||
'Annotation' => true,
|
||||
'Attribute' => true,
|
||||
'Attributes' => true,
|
||||
/* Can we enable this? 'Enum' => true, */
|
||||
'Required' => true,
|
||||
'Target' => true,
|
||||
'NamedArgumentConstructor' => true,
|
||||
];
|
||||
|
||||
private const WidelyUsedNonStandard = [
|
||||
'fix' => true,
|
||||
'fixme' => true,
|
||||
'override' => true,
|
||||
];
|
||||
|
||||
private const PhpDocumentor1 = [
|
||||
'abstract' => true,
|
||||
'access' => true,
|
||||
'code' => true,
|
||||
'deprec' => true,
|
||||
'endcode' => true,
|
||||
'exception' => true,
|
||||
'final' => true,
|
||||
'ingroup' => true,
|
||||
'inheritdoc' => true,
|
||||
'inheritDoc' => true,
|
||||
'magic' => true,
|
||||
'name' => true,
|
||||
'private' => true,
|
||||
'static' => true,
|
||||
'staticvar' => true,
|
||||
'staticVar' => true,
|
||||
'toc' => true,
|
||||
'tutorial' => true,
|
||||
'throw' => true,
|
||||
];
|
||||
|
||||
private const PhpDocumentor2 = [
|
||||
'api' => true,
|
||||
'author' => true,
|
||||
'category' => true,
|
||||
'copyright' => true,
|
||||
'deprecated' => true,
|
||||
'example' => true,
|
||||
'filesource' => true,
|
||||
'global' => true,
|
||||
'ignore' => true,
|
||||
/* Can we enable this? 'index' => true, */
|
||||
'internal' => true,
|
||||
'license' => true,
|
||||
'link' => true,
|
||||
'method' => true,
|
||||
'package' => true,
|
||||
'param' => true,
|
||||
'property' => true,
|
||||
'property-read' => true,
|
||||
'property-write' => true,
|
||||
'return' => true,
|
||||
'see' => true,
|
||||
'since' => true,
|
||||
'source' => true,
|
||||
'subpackage' => true,
|
||||
'throws' => true,
|
||||
'todo' => true,
|
||||
'TODO' => true,
|
||||
'usedby' => true,
|
||||
'uses' => true,
|
||||
'var' => true,
|
||||
'version' => true,
|
||||
];
|
||||
|
||||
private const PHPUnit = [
|
||||
'author' => true,
|
||||
'after' => true,
|
||||
'afterClass' => true,
|
||||
'backupGlobals' => true,
|
||||
'backupStaticAttributes' => true,
|
||||
'before' => true,
|
||||
'beforeClass' => true,
|
||||
'codeCoverageIgnore' => true,
|
||||
'codeCoverageIgnoreStart' => true,
|
||||
'codeCoverageIgnoreEnd' => true,
|
||||
'covers' => true,
|
||||
'coversDefaultClass' => true,
|
||||
'coversNothing' => true,
|
||||
'dataProvider' => true,
|
||||
'depends' => true,
|
||||
'doesNotPerformAssertions' => true,
|
||||
'expectedException' => true,
|
||||
'expectedExceptionCode' => true,
|
||||
'expectedExceptionMessage' => true,
|
||||
'expectedExceptionMessageRegExp' => true,
|
||||
'group' => true,
|
||||
'large' => true,
|
||||
'medium' => true,
|
||||
'preserveGlobalState' => true,
|
||||
'requires' => true,
|
||||
'runTestsInSeparateProcesses' => true,
|
||||
'runInSeparateProcess' => true,
|
||||
'small' => true,
|
||||
'test' => true,
|
||||
'testdox' => true,
|
||||
'testWith' => true,
|
||||
'ticket' => true,
|
||||
'uses' => true,
|
||||
];
|
||||
|
||||
private const PhpCheckStyle = ['SuppressWarnings' => true];
|
||||
|
||||
private const PhpStorm = ['noinspection' => true];
|
||||
|
||||
private const PEAR = ['package_version' => true];
|
||||
|
||||
private const PlainUML = [
|
||||
'startuml' => true,
|
||||
'enduml' => true,
|
||||
];
|
||||
|
||||
private const Symfony = ['experimental' => true];
|
||||
|
||||
private const PhpCodeSniffer = [
|
||||
'codingStandardsIgnoreStart' => true,
|
||||
'codingStandardsIgnoreEnd' => true,
|
||||
];
|
||||
|
||||
private const SlevomatCodingStandard = ['phpcsSuppress' => true];
|
||||
|
||||
private const Phan = ['suppress' => true];
|
||||
|
||||
private const Rector = ['noRector' => true];
|
||||
|
||||
private const StaticAnalysis = [
|
||||
// PHPStan, Psalm
|
||||
'extends' => true,
|
||||
'implements' => true,
|
||||
'readonly' => true,
|
||||
'template' => true,
|
||||
'use' => true,
|
||||
|
||||
// Psalm
|
||||
'pure' => true,
|
||||
'immutable' => true,
|
||||
];
|
||||
|
||||
public const LIST = self::Reserved
|
||||
+ self::WidelyUsedNonStandard
|
||||
+ self::PhpDocumentor1
|
||||
+ self::PhpDocumentor2
|
||||
+ self::PHPUnit
|
||||
+ self::PhpCheckStyle
|
||||
+ self::PhpStorm
|
||||
+ self::PEAR
|
||||
+ self::PlainUML
|
||||
+ self::Symfony
|
||||
+ self::SlevomatCodingStandard
|
||||
+ self::PhpCodeSniffer
|
||||
+ self::Phan
|
||||
+ self::Rector
|
||||
+ self::StaticAnalysis;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
100
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/IndexedReader.php
vendored
Normal file
100
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/IndexedReader.php
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
|
||||
use function call_user_func_array;
|
||||
use function get_class;
|
||||
|
||||
/**
|
||||
* Allows the reader to be used in-place of Doctrine's reader.
|
||||
*/
|
||||
class IndexedReader implements Reader
|
||||
{
|
||||
/** @var Reader */
|
||||
private $delegate;
|
||||
|
||||
public function __construct(Reader $reader)
|
||||
{
|
||||
$this->delegate = $reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(ReflectionClass $class)
|
||||
{
|
||||
$annotations = [];
|
||||
foreach ($this->delegate->getClassAnnotations($class) as $annot) {
|
||||
$annotations[get_class($annot)] = $annot;
|
||||
}
|
||||
|
||||
return $annotations;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(ReflectionClass $class, $annotationName)
|
||||
{
|
||||
return $this->delegate->getClassAnnotation($class, $annotationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(ReflectionMethod $method)
|
||||
{
|
||||
$annotations = [];
|
||||
foreach ($this->delegate->getMethodAnnotations($method) as $annot) {
|
||||
$annotations[get_class($annot)] = $annot;
|
||||
}
|
||||
|
||||
return $annotations;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
return $this->delegate->getMethodAnnotation($method, $annotationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(ReflectionProperty $property)
|
||||
{
|
||||
$annotations = [];
|
||||
foreach ($this->delegate->getPropertyAnnotations($property) as $annot) {
|
||||
$annotations[get_class($annot)] = $annot;
|
||||
}
|
||||
|
||||
return $annotations;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
return $this->delegate->getPropertyAnnotation($property, $annotationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxies all methods to the delegate.
|
||||
*
|
||||
* @param string $method
|
||||
* @param mixed[] $args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
return call_user_func_array([$this->delegate, $method], $args);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Marker interface for PHP7/PHP8 compatible support
|
||||
* for named arguments (and constructor property promotion).
|
||||
*
|
||||
* @deprecated Implementing this interface is deprecated
|
||||
* Use the Annotation @NamedArgumentConstructor instead
|
||||
*/
|
||||
interface NamedArgumentConstructorAnnotation
|
||||
{
|
||||
}
|
92
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PhpParser.php
vendored
Normal file
92
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PhpParser.php
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionFunction;
|
||||
use SplFileObject;
|
||||
|
||||
use function is_file;
|
||||
use function method_exists;
|
||||
use function preg_quote;
|
||||
use function preg_replace;
|
||||
|
||||
/**
|
||||
* Parses a file for namespaces/use/class declarations.
|
||||
*/
|
||||
final class PhpParser
|
||||
{
|
||||
/**
|
||||
* Parses a class.
|
||||
*
|
||||
* @deprecated use parseUseStatements instead
|
||||
*
|
||||
* @param ReflectionClass $class A <code>ReflectionClass</code> object.
|
||||
*
|
||||
* @return array<string, class-string> A list with use statements in the form (Alias => FQN).
|
||||
*/
|
||||
public function parseClass(ReflectionClass $class)
|
||||
{
|
||||
return $this->parseUseStatements($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a class or function for use statements.
|
||||
*
|
||||
* @param ReflectionClass|ReflectionFunction $reflection
|
||||
*
|
||||
* @psalm-return array<string, string> a list with use statements in the form (Alias => FQN).
|
||||
*/
|
||||
public function parseUseStatements($reflection): array
|
||||
{
|
||||
if (method_exists($reflection, 'getUseStatements')) {
|
||||
return $reflection->getUseStatements();
|
||||
}
|
||||
|
||||
$filename = $reflection->getFileName();
|
||||
|
||||
if ($filename === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$content = $this->getFileContent($filename, $reflection->getStartLine());
|
||||
|
||||
if ($content === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$namespace = preg_quote($reflection->getNamespaceName());
|
||||
$content = preg_replace('/^.*?(\bnamespace\s+' . $namespace . '\s*[;{].*)$/s', '\\1', $content);
|
||||
$tokenizer = new TokenParser('<?php ' . $content);
|
||||
|
||||
return $tokenizer->parseUseStatements($reflection->getNamespaceName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content of the file right up to the given line number.
|
||||
*
|
||||
* @param string $filename The name of the file to load.
|
||||
* @param int $lineNumber The number of lines to read from file.
|
||||
*
|
||||
* @return string|null The content of the file or null if the file does not exist.
|
||||
*/
|
||||
private function getFileContent($filename, $lineNumber)
|
||||
{
|
||||
if (! is_file($filename)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$content = '';
|
||||
$lineCnt = 0;
|
||||
$file = new SplFileObject($filename);
|
||||
while (! $file->eof()) {
|
||||
if ($lineCnt++ === $lineNumber) {
|
||||
break;
|
||||
}
|
||||
|
||||
$content .= $file->fgets();
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
232
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PsrCachedReader.php
vendored
Normal file
232
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PsrCachedReader.php
vendored
Normal file
@ -0,0 +1,232 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
use Reflector;
|
||||
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function assert;
|
||||
use function filemtime;
|
||||
use function max;
|
||||
use function rawurlencode;
|
||||
use function time;
|
||||
|
||||
/**
|
||||
* A cache aware annotation reader.
|
||||
*/
|
||||
final class PsrCachedReader implements Reader
|
||||
{
|
||||
/** @var Reader */
|
||||
private $delegate;
|
||||
|
||||
/** @var CacheItemPoolInterface */
|
||||
private $cache;
|
||||
|
||||
/** @var bool */
|
||||
private $debug;
|
||||
|
||||
/** @var array<string, array<object>> */
|
||||
private $loadedAnnotations = [];
|
||||
|
||||
/** @var int[] */
|
||||
private $loadedFilemtimes = [];
|
||||
|
||||
public function __construct(Reader $reader, CacheItemPoolInterface $cache, bool $debug = false)
|
||||
{
|
||||
$this->delegate = $reader;
|
||||
$this->cache = $cache;
|
||||
$this->debug = (bool) $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(ReflectionClass $class)
|
||||
{
|
||||
$cacheKey = $class->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$cacheKey])) {
|
||||
return $this->loadedAnnotations[$cacheKey];
|
||||
}
|
||||
|
||||
$annots = $this->fetchFromCache($cacheKey, $class, 'getClassAnnotations', $class);
|
||||
|
||||
return $this->loadedAnnotations[$cacheKey] = $annots;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(ReflectionClass $class, $annotationName)
|
||||
{
|
||||
foreach ($this->getClassAnnotations($class) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
$cacheKey = $class->getName() . '$' . $property->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$cacheKey])) {
|
||||
return $this->loadedAnnotations[$cacheKey];
|
||||
}
|
||||
|
||||
$annots = $this->fetchFromCache($cacheKey, $class, 'getPropertyAnnotations', $property);
|
||||
|
||||
return $this->loadedAnnotations[$cacheKey] = $annots;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
foreach ($this->getPropertyAnnotations($property) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
$cacheKey = $class->getName() . '#' . $method->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$cacheKey])) {
|
||||
return $this->loadedAnnotations[$cacheKey];
|
||||
}
|
||||
|
||||
$annots = $this->fetchFromCache($cacheKey, $class, 'getMethodAnnotations', $method);
|
||||
|
||||
return $this->loadedAnnotations[$cacheKey] = $annots;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
foreach ($this->getMethodAnnotations($method) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function clearLoadedAnnotations(): void
|
||||
{
|
||||
$this->loadedAnnotations = [];
|
||||
$this->loadedFilemtimes = [];
|
||||
}
|
||||
|
||||
/** @return mixed[] */
|
||||
private function fetchFromCache(
|
||||
string $cacheKey,
|
||||
ReflectionClass $class,
|
||||
string $method,
|
||||
Reflector $reflector
|
||||
): array {
|
||||
$cacheKey = rawurlencode($cacheKey);
|
||||
|
||||
$item = $this->cache->getItem($cacheKey);
|
||||
if (($this->debug && ! $this->refresh($cacheKey, $class)) || ! $item->isHit()) {
|
||||
$this->cache->save($item->set($this->delegate->{$method}($reflector)));
|
||||
}
|
||||
|
||||
return $item->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in debug mode to check if the cache is fresh.
|
||||
*
|
||||
* @return bool Returns true if the cache was fresh, or false if the class
|
||||
* being read was modified since writing to the cache.
|
||||
*/
|
||||
private function refresh(string $cacheKey, ReflectionClass $class): bool
|
||||
{
|
||||
$lastModification = $this->getLastModification($class);
|
||||
if ($lastModification === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$item = $this->cache->getItem('[C]' . $cacheKey);
|
||||
if ($item->isHit() && $item->get() >= $lastModification) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->cache->save($item->set(time()));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time the class was last modified, testing traits and parents
|
||||
*/
|
||||
private function getLastModification(ReflectionClass $class): int
|
||||
{
|
||||
$filename = $class->getFileName();
|
||||
|
||||
if (isset($this->loadedFilemtimes[$filename])) {
|
||||
return $this->loadedFilemtimes[$filename];
|
||||
}
|
||||
|
||||
$parent = $class->getParentClass();
|
||||
|
||||
$lastModification = max(array_merge(
|
||||
[$filename ? filemtime($filename) : 0],
|
||||
array_map(function (ReflectionClass $reflectionTrait): int {
|
||||
return $this->getTraitLastModificationTime($reflectionTrait);
|
||||
}, $class->getTraits()),
|
||||
array_map(function (ReflectionClass $class): int {
|
||||
return $this->getLastModification($class);
|
||||
}, $class->getInterfaces()),
|
||||
$parent ? [$this->getLastModification($parent)] : []
|
||||
));
|
||||
|
||||
assert($lastModification !== false);
|
||||
|
||||
return $this->loadedFilemtimes[$filename] = $lastModification;
|
||||
}
|
||||
|
||||
private function getTraitLastModificationTime(ReflectionClass $reflectionTrait): int
|
||||
{
|
||||
$fileName = $reflectionTrait->getFileName();
|
||||
|
||||
if (isset($this->loadedFilemtimes[$fileName])) {
|
||||
return $this->loadedFilemtimes[$fileName];
|
||||
}
|
||||
|
||||
$lastModificationTime = max(array_merge(
|
||||
[$fileName ? filemtime($fileName) : 0],
|
||||
array_map(function (ReflectionClass $reflectionTrait): int {
|
||||
return $this->getTraitLastModificationTime($reflectionTrait);
|
||||
}, $reflectionTrait->getTraits())
|
||||
));
|
||||
|
||||
assert($lastModificationTime !== false);
|
||||
|
||||
return $this->loadedFilemtimes[$fileName] = $lastModificationTime;
|
||||
}
|
||||
}
|
80
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Reader.php
vendored
Normal file
80
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Reader.php
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Interface for annotation readers.
|
||||
*/
|
||||
interface Reader
|
||||
{
|
||||
/**
|
||||
* Gets the annotations applied to a class.
|
||||
*
|
||||
* @param ReflectionClass $class The ReflectionClass of the class from which
|
||||
* the class annotations should be read.
|
||||
*
|
||||
* @return array<object> An array of Annotations.
|
||||
*/
|
||||
public function getClassAnnotations(ReflectionClass $class);
|
||||
|
||||
/**
|
||||
* Gets a class annotation.
|
||||
*
|
||||
* @param ReflectionClass $class The ReflectionClass of the class from which
|
||||
* the class annotations should be read.
|
||||
* @param class-string<T> $annotationName The name of the annotation.
|
||||
*
|
||||
* @return T|null The Annotation or NULL, if the requested annotation does not exist.
|
||||
*
|
||||
* @template T
|
||||
*/
|
||||
public function getClassAnnotation(ReflectionClass $class, $annotationName);
|
||||
|
||||
/**
|
||||
* Gets the annotations applied to a method.
|
||||
*
|
||||
* @param ReflectionMethod $method The ReflectionMethod of the method from which
|
||||
* the annotations should be read.
|
||||
*
|
||||
* @return array<object> An array of Annotations.
|
||||
*/
|
||||
public function getMethodAnnotations(ReflectionMethod $method);
|
||||
|
||||
/**
|
||||
* Gets a method annotation.
|
||||
*
|
||||
* @param ReflectionMethod $method The ReflectionMethod to read the annotations from.
|
||||
* @param class-string<T> $annotationName The name of the annotation.
|
||||
*
|
||||
* @return T|null The Annotation or NULL, if the requested annotation does not exist.
|
||||
*
|
||||
* @template T
|
||||
*/
|
||||
public function getMethodAnnotation(ReflectionMethod $method, $annotationName);
|
||||
|
||||
/**
|
||||
* Gets the annotations applied to a property.
|
||||
*
|
||||
* @param ReflectionProperty $property The ReflectionProperty of the property
|
||||
* from which the annotations should be read.
|
||||
*
|
||||
* @return array<object> An array of Annotations.
|
||||
*/
|
||||
public function getPropertyAnnotations(ReflectionProperty $property);
|
||||
|
||||
/**
|
||||
* Gets a property annotation.
|
||||
*
|
||||
* @param ReflectionProperty $property The ReflectionProperty to read the annotations from.
|
||||
* @param class-string<T> $annotationName The name of the annotation.
|
||||
*
|
||||
* @return T|null The Annotation or NULL, if the requested annotation does not exist.
|
||||
*
|
||||
* @template T
|
||||
*/
|
||||
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName);
|
||||
}
|
114
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php
vendored
Normal file
114
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Simple Annotation Reader.
|
||||
*
|
||||
* This annotation reader is intended to be used in projects where you have
|
||||
* full-control over all annotations that are available.
|
||||
*
|
||||
* @deprecated Deprecated in favour of using AnnotationReader
|
||||
*/
|
||||
class SimpleAnnotationReader implements Reader
|
||||
{
|
||||
/** @var DocParser */
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* Initializes a new SimpleAnnotationReader.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->parser = new DocParser();
|
||||
$this->parser->setIgnoreNotImportedAnnotations(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a namespace in which we will look for annotations.
|
||||
*
|
||||
* @param string $namespace
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addNamespace($namespace)
|
||||
{
|
||||
$this->parser->addNamespace($namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(ReflectionClass $class)
|
||||
{
|
||||
return $this->parser->parse($class->getDocComment(), 'class ' . $class->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(ReflectionMethod $method)
|
||||
{
|
||||
return $this->parser->parse(
|
||||
$method->getDocComment(),
|
||||
'method ' . $method->getDeclaringClass()->name . '::' . $method->getName() . '()'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(ReflectionProperty $property)
|
||||
{
|
||||
return $this->parser->parse(
|
||||
$property->getDocComment(),
|
||||
'property ' . $property->getDeclaringClass()->name . '::$' . $property->getName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(ReflectionClass $class, $annotationName)
|
||||
{
|
||||
foreach ($this->getClassAnnotations($class) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
foreach ($this->getMethodAnnotations($method) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
foreach ($this->getPropertyAnnotations($property) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
206
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php
vendored
Normal file
206
vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php
vendored
Normal file
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use function array_merge;
|
||||
use function count;
|
||||
use function explode;
|
||||
use function strtolower;
|
||||
use function token_get_all;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
use const T_AS;
|
||||
use const T_COMMENT;
|
||||
use const T_DOC_COMMENT;
|
||||
use const T_NAME_FULLY_QUALIFIED;
|
||||
use const T_NAME_QUALIFIED;
|
||||
use const T_NAMESPACE;
|
||||
use const T_NS_SEPARATOR;
|
||||
use const T_STRING;
|
||||
use const T_USE;
|
||||
use const T_WHITESPACE;
|
||||
|
||||
/**
|
||||
* Parses a file for namespaces/use/class declarations.
|
||||
*/
|
||||
class TokenParser
|
||||
{
|
||||
/**
|
||||
* The token list.
|
||||
*
|
||||
* @phpstan-var list<mixed[]>
|
||||
*/
|
||||
private $tokens;
|
||||
|
||||
/**
|
||||
* The number of tokens.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $numTokens;
|
||||
|
||||
/**
|
||||
* The current array pointer.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $pointer = 0;
|
||||
|
||||
/** @param string $contents */
|
||||
public function __construct($contents)
|
||||
{
|
||||
$this->tokens = token_get_all($contents);
|
||||
|
||||
// The PHP parser sets internal compiler globals for certain things. Annoyingly, the last docblock comment it
|
||||
// saw gets stored in doc_comment. When it comes to compile the next thing to be include()d this stored
|
||||
// doc_comment becomes owned by the first thing the compiler sees in the file that it considers might have a
|
||||
// docblock. If the first thing in the file is a class without a doc block this would cause calls to
|
||||
// getDocBlock() on said class to return our long lost doc_comment. Argh.
|
||||
// To workaround, cause the parser to parse an empty docblock. Sure getDocBlock() will return this, but at least
|
||||
// it's harmless to us.
|
||||
token_get_all("<?php\n/**\n *\n */");
|
||||
|
||||
$this->numTokens = count($this->tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next non whitespace and non comment token.
|
||||
*
|
||||
* @param bool $docCommentIsComment If TRUE then a doc comment is considered a comment and skipped.
|
||||
* If FALSE then only whitespace and normal comments are skipped.
|
||||
*
|
||||
* @return mixed[]|string|null The token if exists, null otherwise.
|
||||
*/
|
||||
public function next($docCommentIsComment = true)
|
||||
{
|
||||
for ($i = $this->pointer; $i < $this->numTokens; $i++) {
|
||||
$this->pointer++;
|
||||
if (
|
||||
$this->tokens[$i][0] === T_WHITESPACE ||
|
||||
$this->tokens[$i][0] === T_COMMENT ||
|
||||
($docCommentIsComment && $this->tokens[$i][0] === T_DOC_COMMENT)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $this->tokens[$i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a single use statement.
|
||||
*
|
||||
* @return array<string, string> A list with all found class names for a use statement.
|
||||
*/
|
||||
public function parseUseStatement()
|
||||
{
|
||||
$groupRoot = '';
|
||||
$class = '';
|
||||
$alias = '';
|
||||
$statements = [];
|
||||
$explicitAlias = false;
|
||||
while (($token = $this->next())) {
|
||||
if (! $explicitAlias && $token[0] === T_STRING) {
|
||||
$class .= $token[1];
|
||||
$alias = $token[1];
|
||||
} elseif ($explicitAlias && $token[0] === T_STRING) {
|
||||
$alias = $token[1];
|
||||
} elseif (
|
||||
PHP_VERSION_ID >= 80000 &&
|
||||
($token[0] === T_NAME_QUALIFIED || $token[0] === T_NAME_FULLY_QUALIFIED)
|
||||
) {
|
||||
$class .= $token[1];
|
||||
|
||||
$classSplit = explode('\\', $token[1]);
|
||||
$alias = $classSplit[count($classSplit) - 1];
|
||||
} elseif ($token[0] === T_NS_SEPARATOR) {
|
||||
$class .= '\\';
|
||||
$alias = '';
|
||||
} elseif ($token[0] === T_AS) {
|
||||
$explicitAlias = true;
|
||||
$alias = '';
|
||||
} elseif ($token === ',') {
|
||||
$statements[strtolower($alias)] = $groupRoot . $class;
|
||||
$class = '';
|
||||
$alias = '';
|
||||
$explicitAlias = false;
|
||||
} elseif ($token === ';') {
|
||||
$statements[strtolower($alias)] = $groupRoot . $class;
|
||||
break;
|
||||
} elseif ($token === '{') {
|
||||
$groupRoot = $class;
|
||||
$class = '';
|
||||
} elseif ($token === '}') {
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all use statements.
|
||||
*
|
||||
* @param string $namespaceName The namespace name of the reflected class.
|
||||
*
|
||||
* @return array<string, string> A list with all found use statements.
|
||||
*/
|
||||
public function parseUseStatements($namespaceName)
|
||||
{
|
||||
$statements = [];
|
||||
while (($token = $this->next())) {
|
||||
if ($token[0] === T_USE) {
|
||||
$statements = array_merge($statements, $this->parseUseStatement());
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($token[0] !== T_NAMESPACE || $this->parseNamespace() !== $namespaceName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get fresh array for new namespace. This is to prevent the parser to collect the use statements
|
||||
// for a previous namespace with the same name. This is the case if a namespace is defined twice
|
||||
// or if a namespace with the same name is commented out.
|
||||
$statements = [];
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace.
|
||||
*
|
||||
* @return string The found namespace.
|
||||
*/
|
||||
public function parseNamespace()
|
||||
{
|
||||
$name = '';
|
||||
while (
|
||||
($token = $this->next()) && ($token[0] === T_STRING || $token[0] === T_NS_SEPARATOR || (
|
||||
PHP_VERSION_ID >= 80000 &&
|
||||
($token[0] === T_NAME_QUALIFIED || $token[0] === T_NAME_FULLY_QUALIFIED)
|
||||
))
|
||||
) {
|
||||
$name .= $token[1];
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class name.
|
||||
*
|
||||
* @return string The found class name.
|
||||
*/
|
||||
public function parseClass()
|
||||
{
|
||||
// Namespaces and class names are tokenized the same: T_STRINGs
|
||||
// separated by T_NS_SEPARATOR so we can use one function to provide
|
||||
// both.
|
||||
return $this->parseNamespace();
|
||||
}
|
||||
}
|
15
vendor/doctrine/annotations/psalm.xml
vendored
Normal file
15
vendor/doctrine/annotations/psalm.xml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<psalm
|
||||
errorLevel="7"
|
||||
resolveFromConfigFile="true"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="https://getpsalm.org/schema/config"
|
||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
||||
>
|
||||
<projectFiles>
|
||||
<directory name="lib/Doctrine/Common/Annotations" />
|
||||
<ignoreFiles>
|
||||
<directory name="vendor" />
|
||||
</ignoreFiles>
|
||||
</projectFiles>
|
||||
</psalm>
|
19
vendor/doctrine/cache/LICENSE
vendored
Normal file
19
vendor/doctrine/cache/LICENSE
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2006-2015 Doctrine Project
|
||||
|
||||
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.
|
13
vendor/doctrine/cache/README.md
vendored
Normal file
13
vendor/doctrine/cache/README.md
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# Doctrine Cache
|
||||
|
||||
[](https://github.com/doctrine/cache/actions)
|
||||
[](https://codecov.io/gh/doctrine/cache/branch/1.10.x)
|
||||
|
||||
[](https://packagist.org/packages/doctrine/cache)
|
||||
[](https://packagist.org/packages/doctrine/cache)
|
||||
|
||||
Cache component extracted from the Doctrine Common project. [Documentation](https://www.doctrine-project.org/projects/doctrine-cache/en/current/index.html)
|
||||
|
||||
This library is deprecated and will no longer receive bug fixes from the
|
||||
Doctrine Project. Please use a different cache library, preferably PSR-6 or
|
||||
PSR-16 instead.
|
27
vendor/doctrine/cache/UPGRADE-1.11.md
vendored
Normal file
27
vendor/doctrine/cache/UPGRADE-1.11.md
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
# Upgrade to 1.11
|
||||
|
||||
doctrine/cache will no longer be maintained and all cache implementations have
|
||||
been marked as deprecated. These implementations will be removed in 2.0, which
|
||||
will only contain interfaces to provide a lightweight package for backward
|
||||
compatibility.
|
||||
|
||||
There are two new classes to use in the `Doctrine\Common\Cache\Psr6` namespace:
|
||||
* The `CacheAdapter` class allows using any Doctrine Cache as PSR-6 cache. This
|
||||
is useful to provide a forward compatibility layer in libraries that accept
|
||||
Doctrine cache implementations and switch to PSR-6.
|
||||
* The `DoctrineProvider` class allows using any PSR-6 cache as Doctrine cache.
|
||||
This implementation is designed for libraries that leak the cache and want to
|
||||
switch to allowing PSR-6 implementations. This class is design to be used
|
||||
during the transition phase of sunsetting doctrine/cache support.
|
||||
|
||||
A full example to setup a filesystem based PSR-6 cache with symfony/cache
|
||||
using the `DoctrineProvider` to convert back to Doctrine's `Cache` interface:
|
||||
|
||||
```php
|
||||
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
|
||||
$cachePool = new FilesystemAdapter();
|
||||
$cache = DoctrineProvider::wrap($cachePool);
|
||||
// $cache instanceof \Doctrine\Common\Cache\Cache
|
||||
```
|
16
vendor/doctrine/cache/UPGRADE-1.4.md
vendored
Normal file
16
vendor/doctrine/cache/UPGRADE-1.4.md
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# Upgrade to 1.4
|
||||
|
||||
## Minor BC Break: `Doctrine\Common\Cache\FileCache#$extension` is now `private`.
|
||||
|
||||
If you need to override the value of `Doctrine\Common\Cache\FileCache#$extension`, then use the
|
||||
second parameter of `Doctrine\Common\Cache\FileCache#__construct()` instead of overriding
|
||||
the property in your own implementation.
|
||||
|
||||
## Minor BC Break: file based caches paths changed
|
||||
|
||||
`Doctrine\Common\Cache\FileCache`, `Doctrine\Common\Cache\PhpFileCache` and
|
||||
`Doctrine\Common\Cache\FilesystemCache` are using a different cache paths structure.
|
||||
|
||||
If you rely on warmed up caches for deployments, consider that caches generated
|
||||
with `doctrine/cache` `<1.4` are not compatible with the new directory structure,
|
||||
and will be ignored.
|
50
vendor/doctrine/cache/composer.json
vendored
Normal file
50
vendor/doctrine/cache/composer.json
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "doctrine/cache",
|
||||
"type": "library",
|
||||
"description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.",
|
||||
"keywords": [
|
||||
"php",
|
||||
"cache",
|
||||
"caching",
|
||||
"abstraction",
|
||||
"redis",
|
||||
"memcached",
|
||||
"couchdb",
|
||||
"xcache",
|
||||
"apcu"
|
||||
],
|
||||
"homepage": "https://www.doctrine-project.org/projects/cache.html",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"},
|
||||
{"name": "Roman Borschel", "email": "roman@code-factory.org"},
|
||||
{"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"},
|
||||
{"name": "Jonathan Wage", "email": "jonwage@gmail.com"},
|
||||
{"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"}
|
||||
],
|
||||
"require": {
|
||||
"php": "~7.1 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
|
||||
"doctrine/coding-standard": "^9",
|
||||
"psr/cache": "^1.0 || ^2.0 || ^3.0",
|
||||
"cache/integration-tests": "dev-master",
|
||||
"symfony/cache": "^4.4 || ^5.4 || ^6",
|
||||
"symfony/var-exporter": "^4.4 || ^5.4 || ^6"
|
||||
},
|
||||
"conflict": {
|
||||
"doctrine/common": ">2.2,<2.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" }
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": { "Doctrine\\Tests\\": "tests/Doctrine/Tests" }
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||
}
|
||||
}
|
||||
}
|
90
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Cache.php
vendored
Normal file
90
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Cache.php
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache drivers.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
interface Cache
|
||||
{
|
||||
public const STATS_HITS = 'hits';
|
||||
public const STATS_MISSES = 'misses';
|
||||
public const STATS_UPTIME = 'uptime';
|
||||
public const STATS_MEMORY_USAGE = 'memory_usage';
|
||||
public const STATS_MEMORY_AVAILABLE = 'memory_available';
|
||||
/**
|
||||
* Only for backward compatibility (may be removed in next major release)
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public const STATS_MEMORY_AVAILIABLE = 'memory_available';
|
||||
|
||||
/**
|
||||
* Fetches an entry from the cache.
|
||||
*
|
||||
* @param string $id The id of the cache entry to fetch.
|
||||
*
|
||||
* @return mixed The cached data or FALSE, if no cache entry exists for the given id.
|
||||
*/
|
||||
public function fetch($id);
|
||||
|
||||
/**
|
||||
* Tests if an entry exists in the cache.
|
||||
*
|
||||
* @param string $id The cache id of the entry to check for.
|
||||
*
|
||||
* @return bool TRUE if a cache entry exists for the given cache id, FALSE otherwise.
|
||||
*/
|
||||
public function contains($id);
|
||||
|
||||
/**
|
||||
* Puts data into the cache.
|
||||
*
|
||||
* If a cache entry with the given id already exists, its data will be replaced.
|
||||
*
|
||||
* @param string $id The cache id.
|
||||
* @param mixed $data The cache entry/data.
|
||||
* @param int $lifeTime The lifetime in number of seconds for this cache entry.
|
||||
* If zero (the default), the entry never expires (although it may be deleted from the cache
|
||||
* to make place for other entries).
|
||||
*
|
||||
* @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise.
|
||||
*/
|
||||
public function save($id, $data, $lifeTime = 0);
|
||||
|
||||
/**
|
||||
* Deletes a cache entry.
|
||||
*
|
||||
* @param string $id The cache id.
|
||||
*
|
||||
* @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise.
|
||||
* Deleting a non-existing entry is considered successful.
|
||||
*/
|
||||
public function delete($id);
|
||||
|
||||
/**
|
||||
* Retrieves cached information from the data store.
|
||||
*
|
||||
* The server's statistics array has the following values:
|
||||
*
|
||||
* - <b>hits</b>
|
||||
* Number of keys that have been requested and found present.
|
||||
*
|
||||
* - <b>misses</b>
|
||||
* Number of items that have been requested and not found.
|
||||
*
|
||||
* - <b>uptime</b>
|
||||
* Time that the server is running.
|
||||
*
|
||||
* - <b>memory_usage</b>
|
||||
* Memory used by this server to store items.
|
||||
*
|
||||
* - <b>memory_available</b>
|
||||
* Memory allowed to use for storage.
|
||||
*
|
||||
* @return mixed[]|null An associative array with server's statistics if available, NULL otherwise.
|
||||
*/
|
||||
public function getStats();
|
||||
}
|
325
vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php
vendored
Normal file
325
vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php
vendored
Normal file
@ -0,0 +1,325 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
use function array_combine;
|
||||
use function array_key_exists;
|
||||
use function array_map;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Base class for cache provider implementations.
|
||||
*/
|
||||
abstract class CacheProvider implements Cache, FlushableCache, ClearableCache, MultiOperationCache
|
||||
{
|
||||
public const DOCTRINE_NAMESPACE_CACHEKEY = 'DoctrineNamespaceCacheKey[%s]';
|
||||
|
||||
/**
|
||||
* The namespace to prefix all cache ids with.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $namespace = '';
|
||||
|
||||
/**
|
||||
* The namespace version.
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
private $namespaceVersion;
|
||||
|
||||
/**
|
||||
* Sets the namespace to prefix all cache ids with.
|
||||
*
|
||||
* @param string $namespace
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setNamespace($namespace)
|
||||
{
|
||||
$this->namespace = (string) $namespace;
|
||||
$this->namespaceVersion = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the namespace that prefixes all cache ids.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetch($id)
|
||||
{
|
||||
return $this->doFetch($this->getNamespacedId($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetchMultiple(array $keys)
|
||||
{
|
||||
if (empty($keys)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// note: the array_combine() is in place to keep an association between our $keys and the $namespacedKeys
|
||||
$namespacedKeys = array_combine($keys, array_map([$this, 'getNamespacedId'], $keys));
|
||||
$items = $this->doFetchMultiple($namespacedKeys);
|
||||
$foundItems = [];
|
||||
|
||||
// no internal array function supports this sort of mapping: needs to be iterative
|
||||
// this filters and combines keys in one pass
|
||||
foreach ($namespacedKeys as $requestedKey => $namespacedKey) {
|
||||
if (! isset($items[$namespacedKey]) && ! array_key_exists($namespacedKey, $items)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$foundItems[$requestedKey] = $items[$namespacedKey];
|
||||
}
|
||||
|
||||
return $foundItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function saveMultiple(array $keysAndValues, $lifetime = 0)
|
||||
{
|
||||
$namespacedKeysAndValues = [];
|
||||
foreach ($keysAndValues as $key => $value) {
|
||||
$namespacedKeysAndValues[$this->getNamespacedId($key)] = $value;
|
||||
}
|
||||
|
||||
return $this->doSaveMultiple($namespacedKeysAndValues, $lifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function contains($id)
|
||||
{
|
||||
return $this->doContains($this->getNamespacedId($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save($id, $data, $lifeTime = 0)
|
||||
{
|
||||
return $this->doSave($this->getNamespacedId($id), $data, $lifeTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteMultiple(array $keys)
|
||||
{
|
||||
return $this->doDeleteMultiple(array_map([$this, 'getNamespacedId'], $keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return $this->doDelete($this->getNamespacedId($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStats()
|
||||
{
|
||||
return $this->doGetStats();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function flushAll()
|
||||
{
|
||||
return $this->doFlush();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function deleteAll()
|
||||
{
|
||||
$namespaceCacheKey = $this->getNamespaceCacheKey();
|
||||
$namespaceVersion = $this->getNamespaceVersion() + 1;
|
||||
|
||||
if ($this->doSave($namespaceCacheKey, $namespaceVersion)) {
|
||||
$this->namespaceVersion = $namespaceVersion;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefixes the passed id with the configured namespace value.
|
||||
*
|
||||
* @param string $id The id to namespace.
|
||||
*
|
||||
* @return string The namespaced id.
|
||||
*/
|
||||
private function getNamespacedId(string $id): string
|
||||
{
|
||||
$namespaceVersion = $this->getNamespaceVersion();
|
||||
|
||||
return sprintf('%s[%s][%s]', $this->namespace, $id, $namespaceVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the namespace cache key.
|
||||
*/
|
||||
private function getNamespaceCacheKey(): string
|
||||
{
|
||||
return sprintf(self::DOCTRINE_NAMESPACE_CACHEKEY, $this->namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the namespace version.
|
||||
*/
|
||||
private function getNamespaceVersion(): int
|
||||
{
|
||||
if ($this->namespaceVersion !== null) {
|
||||
return $this->namespaceVersion;
|
||||
}
|
||||
|
||||
$namespaceCacheKey = $this->getNamespaceCacheKey();
|
||||
$this->namespaceVersion = (int) $this->doFetch($namespaceCacheKey) ?: 1;
|
||||
|
||||
return $this->namespaceVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation of doFetchMultiple. Each driver that supports multi-get should owerwrite it.
|
||||
*
|
||||
* @param string[] $keys Array of keys to retrieve from cache
|
||||
*
|
||||
* @return mixed[] Array of values retrieved for the given keys.
|
||||
*/
|
||||
protected function doFetchMultiple(array $keys)
|
||||
{
|
||||
$returnValues = [];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$item = $this->doFetch($key);
|
||||
if ($item === false && ! $this->doContains($key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$returnValues[$key] = $item;
|
||||
}
|
||||
|
||||
return $returnValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches an entry from the cache.
|
||||
*
|
||||
* @param string $id The id of the cache entry to fetch.
|
||||
*
|
||||
* @return mixed|false The cached data or FALSE, if no cache entry exists for the given id.
|
||||
*/
|
||||
abstract protected function doFetch($id);
|
||||
|
||||
/**
|
||||
* Tests if an entry exists in the cache.
|
||||
*
|
||||
* @param string $id The cache id of the entry to check for.
|
||||
*
|
||||
* @return bool TRUE if a cache entry exists for the given cache id, FALSE otherwise.
|
||||
*/
|
||||
abstract protected function doContains($id);
|
||||
|
||||
/**
|
||||
* Default implementation of doSaveMultiple. Each driver that supports multi-put should override it.
|
||||
*
|
||||
* @param mixed[] $keysAndValues Array of keys and values to save in cache
|
||||
* @param int $lifetime The lifetime. If != 0, sets a specific lifetime for these
|
||||
* cache entries (0 => infinite lifeTime).
|
||||
*
|
||||
* @return bool TRUE if the operation was successful, FALSE if it wasn't.
|
||||
*/
|
||||
protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
|
||||
{
|
||||
$success = true;
|
||||
|
||||
foreach ($keysAndValues as $key => $value) {
|
||||
if ($this->doSave($key, $value, $lifetime)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$success = false;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts data into the cache.
|
||||
*
|
||||
* @param string $id The cache id.
|
||||
* @param string $data The cache entry/data.
|
||||
* @param int $lifeTime The lifetime. If != 0, sets a specific lifetime for this
|
||||
* cache entry (0 => infinite lifeTime).
|
||||
*
|
||||
* @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise.
|
||||
*/
|
||||
abstract protected function doSave($id, $data, $lifeTime = 0);
|
||||
|
||||
/**
|
||||
* Default implementation of doDeleteMultiple. Each driver that supports multi-delete should override it.
|
||||
*
|
||||
* @param string[] $keys Array of keys to delete from cache
|
||||
*
|
||||
* @return bool TRUE if the operation was successful, FALSE if it wasn't
|
||||
*/
|
||||
protected function doDeleteMultiple(array $keys)
|
||||
{
|
||||
$success = true;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if ($this->doDelete($key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$success = false;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a cache entry.
|
||||
*
|
||||
* @param string $id The cache id.
|
||||
*
|
||||
* @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise.
|
||||
*/
|
||||
abstract protected function doDelete($id);
|
||||
|
||||
/**
|
||||
* Flushes all cache entries.
|
||||
*
|
||||
* @return bool TRUE if the cache entries were successfully flushed, FALSE otherwise.
|
||||
*/
|
||||
abstract protected function doFlush();
|
||||
|
||||
/**
|
||||
* Retrieves cached information from the data store.
|
||||
*
|
||||
* @return mixed[]|null An associative array with server's statistics if available, NULL otherwise.
|
||||
*/
|
||||
abstract protected function doGetStats();
|
||||
}
|
21
vendor/doctrine/cache/lib/Doctrine/Common/Cache/ClearableCache.php
vendored
Normal file
21
vendor/doctrine/cache/lib/Doctrine/Common/Cache/ClearableCache.php
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache that can be flushed.
|
||||
*
|
||||
* Intended to be used for partial clearing of a cache namespace. For a more
|
||||
* global "flushing", see {@see FlushableCache}.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
interface ClearableCache
|
||||
{
|
||||
/**
|
||||
* Deletes all cache entries in the current cache namespace.
|
||||
*
|
||||
* @return bool TRUE if the cache entries were successfully deleted, FALSE otherwise.
|
||||
*/
|
||||
public function deleteAll();
|
||||
}
|
18
vendor/doctrine/cache/lib/Doctrine/Common/Cache/FlushableCache.php
vendored
Normal file
18
vendor/doctrine/cache/lib/Doctrine/Common/Cache/FlushableCache.php
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache that can be flushed.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
interface FlushableCache
|
||||
{
|
||||
/**
|
||||
* Flushes all cache entries, globally.
|
||||
*
|
||||
* @return bool TRUE if the cache entries were successfully flushed, FALSE otherwise.
|
||||
*/
|
||||
public function flushAll();
|
||||
}
|
22
vendor/doctrine/cache/lib/Doctrine/Common/Cache/MultiDeleteCache.php
vendored
Normal file
22
vendor/doctrine/cache/lib/Doctrine/Common/Cache/MultiDeleteCache.php
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache drivers that allows to put many items at once.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
interface MultiDeleteCache
|
||||
{
|
||||
/**
|
||||
* Deletes several cache entries.
|
||||
*
|
||||
* @param string[] $keys Array of keys to delete from cache
|
||||
*
|
||||
* @return bool TRUE if the operation was successful, FALSE if it wasn't.
|
||||
*/
|
||||
public function deleteMultiple(array $keys);
|
||||
}
|
23
vendor/doctrine/cache/lib/Doctrine/Common/Cache/MultiGetCache.php
vendored
Normal file
23
vendor/doctrine/cache/lib/Doctrine/Common/Cache/MultiGetCache.php
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache drivers that allows to get many items at once.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
interface MultiGetCache
|
||||
{
|
||||
/**
|
||||
* Returns an associative array of values for keys is found in cache.
|
||||
*
|
||||
* @param string[] $keys Array of keys to retrieve from cache
|
||||
*
|
||||
* @return mixed[] Array of retrieved values, indexed by the specified keys.
|
||||
* Values that couldn't be retrieved are not contained in this array.
|
||||
*/
|
||||
public function fetchMultiple(array $keys);
|
||||
}
|
12
vendor/doctrine/cache/lib/Doctrine/Common/Cache/MultiOperationCache.php
vendored
Normal file
12
vendor/doctrine/cache/lib/Doctrine/Common/Cache/MultiOperationCache.php
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache drivers that supports multiple items manipulation.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
interface MultiOperationCache extends MultiGetCache, MultiDeleteCache, MultiPutCache
|
||||
{
|
||||
}
|
24
vendor/doctrine/cache/lib/Doctrine/Common/Cache/MultiPutCache.php
vendored
Normal file
24
vendor/doctrine/cache/lib/Doctrine/Common/Cache/MultiPutCache.php
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache drivers that allows to put many items at once.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
interface MultiPutCache
|
||||
{
|
||||
/**
|
||||
* Returns a boolean value indicating if the operation succeeded.
|
||||
*
|
||||
* @param mixed[] $keysAndValues Array of keys and values to save in cache
|
||||
* @param int $lifetime The lifetime. If != 0, sets a specific lifetime for these
|
||||
* cache entries (0 => infinite lifeTime).
|
||||
*
|
||||
* @return bool TRUE if the operation was successful, FALSE if it wasn't.
|
||||
*/
|
||||
public function saveMultiple(array $keysAndValues, $lifetime = 0);
|
||||
}
|
340
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Psr6/CacheAdapter.php
vendored
Normal file
340
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Psr6/CacheAdapter.php
vendored
Normal file
@ -0,0 +1,340 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache\Psr6;
|
||||
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Doctrine\Common\Cache\ClearableCache;
|
||||
use Doctrine\Common\Cache\MultiDeleteCache;
|
||||
use Doctrine\Common\Cache\MultiGetCache;
|
||||
use Doctrine\Common\Cache\MultiPutCache;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Cache\DoctrineProvider as SymfonyDoctrineProvider;
|
||||
|
||||
use function array_key_exists;
|
||||
use function assert;
|
||||
use function count;
|
||||
use function current;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function microtime;
|
||||
use function sprintf;
|
||||
use function strpbrk;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
final class CacheAdapter implements CacheItemPoolInterface
|
||||
{
|
||||
private const RESERVED_CHARACTERS = '{}()/\@:';
|
||||
|
||||
/** @var Cache */
|
||||
private $cache;
|
||||
|
||||
/** @var array<CacheItem|TypedCacheItem> */
|
||||
private $deferredItems = [];
|
||||
|
||||
public static function wrap(Cache $cache): CacheItemPoolInterface
|
||||
{
|
||||
if ($cache instanceof DoctrineProvider && ! $cache->getNamespace()) {
|
||||
return $cache->getPool();
|
||||
}
|
||||
|
||||
if ($cache instanceof SymfonyDoctrineProvider && ! $cache->getNamespace()) {
|
||||
$getPool = function () {
|
||||
// phpcs:ignore Squiz.Scope.StaticThisUsage.Found
|
||||
return $this->pool;
|
||||
};
|
||||
|
||||
return $getPool->bindTo($cache, SymfonyDoctrineProvider::class)();
|
||||
}
|
||||
|
||||
return new self($cache);
|
||||
}
|
||||
|
||||
private function __construct(Cache $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public function getCache(): Cache
|
||||
{
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getItem($key): CacheItemInterface
|
||||
{
|
||||
assert(self::validKey($key));
|
||||
|
||||
if (isset($this->deferredItems[$key])) {
|
||||
$this->commit();
|
||||
}
|
||||
|
||||
$value = $this->cache->fetch($key);
|
||||
|
||||
if (PHP_VERSION_ID >= 80000) {
|
||||
if ($value !== false) {
|
||||
return new TypedCacheItem($key, $value, true);
|
||||
}
|
||||
|
||||
return new TypedCacheItem($key, null, false);
|
||||
}
|
||||
|
||||
if ($value !== false) {
|
||||
return new CacheItem($key, $value, true);
|
||||
}
|
||||
|
||||
return new CacheItem($key, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getItems(array $keys = []): array
|
||||
{
|
||||
if ($this->deferredItems) {
|
||||
$this->commit();
|
||||
}
|
||||
|
||||
assert(self::validKeys($keys));
|
||||
|
||||
$values = $this->doFetchMultiple($keys);
|
||||
$items = [];
|
||||
|
||||
if (PHP_VERSION_ID >= 80000) {
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $values)) {
|
||||
$items[$key] = new TypedCacheItem($key, $values[$key], true);
|
||||
} else {
|
||||
$items[$key] = new TypedCacheItem($key, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $values)) {
|
||||
$items[$key] = new CacheItem($key, $values[$key], true);
|
||||
} else {
|
||||
$items[$key] = new CacheItem($key, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hasItem($key): bool
|
||||
{
|
||||
assert(self::validKey($key));
|
||||
|
||||
if (isset($this->deferredItems[$key])) {
|
||||
$this->commit();
|
||||
}
|
||||
|
||||
return $this->cache->contains($key);
|
||||
}
|
||||
|
||||
public function clear(): bool
|
||||
{
|
||||
$this->deferredItems = [];
|
||||
|
||||
if (! $this->cache instanceof ClearableCache) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->cache->deleteAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function deleteItem($key): bool
|
||||
{
|
||||
assert(self::validKey($key));
|
||||
unset($this->deferredItems[$key]);
|
||||
|
||||
return $this->cache->delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function deleteItems(array $keys): bool
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
assert(self::validKey($key));
|
||||
unset($this->deferredItems[$key]);
|
||||
}
|
||||
|
||||
return $this->doDeleteMultiple($keys);
|
||||
}
|
||||
|
||||
public function save(CacheItemInterface $item): bool
|
||||
{
|
||||
return $this->saveDeferred($item) && $this->commit();
|
||||
}
|
||||
|
||||
public function saveDeferred(CacheItemInterface $item): bool
|
||||
{
|
||||
if (! $item instanceof CacheItem && ! $item instanceof TypedCacheItem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->deferredItems[$item->getKey()] = $item;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function commit(): bool
|
||||
{
|
||||
if (! $this->deferredItems) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$now = microtime(true);
|
||||
$itemsCount = 0;
|
||||
$byLifetime = [];
|
||||
$expiredKeys = [];
|
||||
|
||||
foreach ($this->deferredItems as $key => $item) {
|
||||
$lifetime = ($item->getExpiry() ?? $now) - $now;
|
||||
|
||||
if ($lifetime < 0) {
|
||||
$expiredKeys[] = $key;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
++$itemsCount;
|
||||
$byLifetime[(int) $lifetime][$key] = $item->get();
|
||||
}
|
||||
|
||||
$this->deferredItems = [];
|
||||
|
||||
switch (count($expiredKeys)) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
$this->cache->delete(current($expiredKeys));
|
||||
break;
|
||||
default:
|
||||
$this->doDeleteMultiple($expiredKeys);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($itemsCount === 1) {
|
||||
return $this->cache->save($key, $item->get(), (int) $lifetime);
|
||||
}
|
||||
|
||||
$success = true;
|
||||
foreach ($byLifetime as $lifetime => $values) {
|
||||
$success = $this->doSaveMultiple($values, $lifetime) && $success;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $key
|
||||
*/
|
||||
private static function validKey($key): bool
|
||||
{
|
||||
if (! is_string($key)) {
|
||||
throw new InvalidArgument(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||
}
|
||||
|
||||
if ($key === '') {
|
||||
throw new InvalidArgument('Cache key length must be greater than zero.');
|
||||
}
|
||||
|
||||
if (strpbrk($key, self::RESERVED_CHARACTERS) !== false) {
|
||||
throw new InvalidArgument(sprintf('Cache key "%s" contains reserved characters "%s".', $key, self::RESERVED_CHARACTERS));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $keys
|
||||
*/
|
||||
private static function validKeys(array $keys): bool
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
self::validKey($key);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $keys
|
||||
*/
|
||||
private function doDeleteMultiple(array $keys): bool
|
||||
{
|
||||
if ($this->cache instanceof MultiDeleteCache) {
|
||||
return $this->cache->deleteMultiple($keys);
|
||||
}
|
||||
|
||||
$success = true;
|
||||
foreach ($keys as $key) {
|
||||
$success = $this->cache->delete($key) && $success;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $keys
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function doFetchMultiple(array $keys): array
|
||||
{
|
||||
if ($this->cache instanceof MultiGetCache) {
|
||||
return $this->cache->fetchMultiple($keys);
|
||||
}
|
||||
|
||||
$values = [];
|
||||
foreach ($keys as $key) {
|
||||
$value = $this->cache->fetch($key);
|
||||
if (! $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$values[$key] = $value;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $keysAndValues
|
||||
*/
|
||||
private function doSaveMultiple(array $keysAndValues, int $lifetime = 0): bool
|
||||
{
|
||||
if ($this->cache instanceof MultiPutCache) {
|
||||
return $this->cache->saveMultiple($keysAndValues, $lifetime);
|
||||
}
|
||||
|
||||
$success = true;
|
||||
foreach ($keysAndValues as $key => $value) {
|
||||
$success = $this->cache->save($key, $value, $lifetime) && $success;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
}
|
118
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Psr6/CacheItem.php
vendored
Normal file
118
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Psr6/CacheItem.php
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache\Psr6;
|
||||
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use TypeError;
|
||||
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_int;
|
||||
use function is_object;
|
||||
use function microtime;
|
||||
use function sprintf;
|
||||
|
||||
final class CacheItem implements CacheItemInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $key;
|
||||
/** @var mixed */
|
||||
private $value;
|
||||
/** @var bool */
|
||||
private $isHit;
|
||||
/** @var float|null */
|
||||
private $expiry;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param mixed $data
|
||||
*/
|
||||
public function __construct(string $key, $data, bool $isHit)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->value = $data;
|
||||
$this->isHit = $isHit;
|
||||
}
|
||||
|
||||
public function getKey(): string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function isHit(): bool
|
||||
{
|
||||
return $this->isHit;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set($value): self
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function expiresAt($expiration): self
|
||||
{
|
||||
if ($expiration === null) {
|
||||
$this->expiry = null;
|
||||
} elseif ($expiration instanceof DateTimeInterface) {
|
||||
$this->expiry = (float) $expiration->format('U.u');
|
||||
} else {
|
||||
throw new TypeError(sprintf(
|
||||
'Expected $expiration to be an instance of DateTimeInterface or null, got %s',
|
||||
is_object($expiration) ? get_class($expiration) : gettype($expiration)
|
||||
));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function expiresAfter($time): self
|
||||
{
|
||||
if ($time === null) {
|
||||
$this->expiry = null;
|
||||
} elseif ($time instanceof DateInterval) {
|
||||
$this->expiry = microtime(true) + DateTime::createFromFormat('U', 0)->add($time)->format('U.u');
|
||||
} elseif (is_int($time)) {
|
||||
$this->expiry = $time + microtime(true);
|
||||
} else {
|
||||
throw new TypeError(sprintf(
|
||||
'Expected $time to be either an integer, an instance of DateInterval or null, got %s',
|
||||
is_object($time) ? get_class($time) : gettype($time)
|
||||
));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function getExpiry(): ?float
|
||||
{
|
||||
return $this->expiry;
|
||||
}
|
||||
}
|
135
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Psr6/DoctrineProvider.php
vendored
Normal file
135
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Psr6/DoctrineProvider.php
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
<?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 Doctrine\Common\Cache\Psr6;
|
||||
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Doctrine\Common\Cache\CacheProvider;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Cache\Adapter\DoctrineAdapter as SymfonyDoctrineAdapter;
|
||||
use Symfony\Contracts\Service\ResetInterface;
|
||||
|
||||
use function rawurlencode;
|
||||
|
||||
/**
|
||||
* This class was copied from the Symfony Framework, see the original copyright
|
||||
* notice above. The code is distributed subject to the license terms in
|
||||
* https://github.com/symfony/symfony/blob/ff0cf61278982539c49e467db9ab13cbd342f76d/LICENSE
|
||||
*/
|
||||
final class DoctrineProvider extends CacheProvider
|
||||
{
|
||||
/** @var CacheItemPoolInterface */
|
||||
private $pool;
|
||||
|
||||
public static function wrap(CacheItemPoolInterface $pool): Cache
|
||||
{
|
||||
if ($pool instanceof CacheAdapter) {
|
||||
return $pool->getCache();
|
||||
}
|
||||
|
||||
if ($pool instanceof SymfonyDoctrineAdapter) {
|
||||
$getCache = function () {
|
||||
// phpcs:ignore Squiz.Scope.StaticThisUsage.Found
|
||||
return $this->provider;
|
||||
};
|
||||
|
||||
return $getCache->bindTo($pool, SymfonyDoctrineAdapter::class)();
|
||||
}
|
||||
|
||||
return new self($pool);
|
||||
}
|
||||
|
||||
private function __construct(CacheItemPoolInterface $pool)
|
||||
{
|
||||
$this->pool = $pool;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public function getPool(): CacheItemPoolInterface
|
||||
{
|
||||
return $this->pool;
|
||||
}
|
||||
|
||||
public function reset(): void
|
||||
{
|
||||
if ($this->pool instanceof ResetInterface) {
|
||||
$this->pool->reset();
|
||||
}
|
||||
|
||||
$this->setNamespace($this->getNamespace());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
$item = $this->pool->getItem(rawurlencode($id));
|
||||
|
||||
return $item->isHit() ? $item->get() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return $this->pool->hasItem(rawurlencode($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
$item = $this->pool->getItem(rawurlencode($id));
|
||||
|
||||
if (0 < $lifeTime) {
|
||||
$item->expiresAfter($lifeTime);
|
||||
}
|
||||
|
||||
return $this->pool->save($item->set($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return $this->pool->deleteItem(rawurlencode($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
return $this->pool->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
13
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Psr6/InvalidArgument.php
vendored
Normal file
13
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Psr6/InvalidArgument.php
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache\Psr6;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Psr\Cache\InvalidArgumentException as PsrInvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class InvalidArgument extends InvalidArgumentException implements PsrInvalidArgumentException
|
||||
{
|
||||
}
|
99
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Psr6/TypedCacheItem.php
vendored
Normal file
99
vendor/doctrine/cache/lib/Doctrine/Common/Cache/Psr6/TypedCacheItem.php
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache\Psr6;
|
||||
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use TypeError;
|
||||
|
||||
use function get_debug_type;
|
||||
use function is_int;
|
||||
use function microtime;
|
||||
use function sprintf;
|
||||
|
||||
final class TypedCacheItem implements CacheItemInterface
|
||||
{
|
||||
private ?float $expiry = null;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __construct(
|
||||
private string $key,
|
||||
private mixed $value,
|
||||
private bool $isHit,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getKey(): string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
public function get(): mixed
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function isHit(): bool
|
||||
{
|
||||
return $this->isHit;
|
||||
}
|
||||
|
||||
public function set(mixed $value): static
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function expiresAt($expiration): static
|
||||
{
|
||||
if ($expiration === null) {
|
||||
$this->expiry = null;
|
||||
} elseif ($expiration instanceof DateTimeInterface) {
|
||||
$this->expiry = (float) $expiration->format('U.u');
|
||||
} else {
|
||||
throw new TypeError(sprintf(
|
||||
'Expected $expiration to be an instance of DateTimeInterface or null, got %s',
|
||||
get_debug_type($expiration)
|
||||
));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function expiresAfter($time): static
|
||||
{
|
||||
if ($time === null) {
|
||||
$this->expiry = null;
|
||||
} elseif ($time instanceof DateInterval) {
|
||||
$this->expiry = microtime(true) + DateTime::createFromFormat('U', 0)->add($time)->format('U.u');
|
||||
} elseif (is_int($time)) {
|
||||
$this->expiry = $time + microtime(true);
|
||||
} else {
|
||||
throw new TypeError(sprintf(
|
||||
'Expected $time to be either an integer, an instance of DateInterval or null, got %s',
|
||||
get_debug_type($time)
|
||||
));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function getExpiry(): ?float
|
||||
{
|
||||
return $this->expiry;
|
||||
}
|
||||
}
|
43
vendor/doctrine/collections/.doctrine-project.json
vendored
Normal file
43
vendor/doctrine/collections/.doctrine-project.json
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"active": true,
|
||||
"name": "Collections",
|
||||
"slug": "collections",
|
||||
"docsSlug": "doctrine-collections",
|
||||
"versions": [
|
||||
{
|
||||
"name": "3.0",
|
||||
"branchName": "3.0.x",
|
||||
"slug": "latest",
|
||||
"upcoming": true
|
||||
},
|
||||
{
|
||||
"name": "2.1",
|
||||
"branchName": "2.1.x",
|
||||
"slug": "stable",
|
||||
"current": true
|
||||
},
|
||||
{
|
||||
"name": "2.0",
|
||||
"branchName": "2.0.x",
|
||||
"slug": "2.0",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "1.8",
|
||||
"branchName": "1.8.x",
|
||||
"slug": "1.8"
|
||||
},
|
||||
{
|
||||
"name": "1.7",
|
||||
"branchName": "1.7.x",
|
||||
"slug": "1.7",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "1.6",
|
||||
"branchName": "1.6.x",
|
||||
"slug": "1.6",
|
||||
"maintained": false
|
||||
}
|
||||
]
|
||||
}
|
44
vendor/doctrine/collections/CONTRIBUTING.md
vendored
Normal file
44
vendor/doctrine/collections/CONTRIBUTING.md
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
# Contribute to Doctrine
|
||||
|
||||
Thank you for contributing to Doctrine!
|
||||
|
||||
Before we can merge your Pull-Request here are some guidelines that you need to follow.
|
||||
These guidelines exist not to annoy you, but to keep the code base clean,
|
||||
unified and future proof.
|
||||
|
||||
## Coding Standard
|
||||
|
||||
We use the [Doctrine Coding Standard](https://github.com/doctrine/coding-standard).
|
||||
|
||||
## Unit-Tests
|
||||
|
||||
Please try to add a test for your pull-request.
|
||||
|
||||
* If you want to contribute new functionality add unit- or functional tests
|
||||
depending on the scope of the feature.
|
||||
|
||||
You can run the unit-tests by calling ``vendor/bin/phpunit`` from the root of the project.
|
||||
It will run all the project tests.
|
||||
|
||||
In order to do that, you will need a fresh copy of doctrine/collections, and you
|
||||
will have to run a composer installation in the project:
|
||||
|
||||
```sh
|
||||
git clone git@github.com:doctrine/collections.git
|
||||
cd collections
|
||||
curl -sS https://getcomposer.org/installer | php --
|
||||
./composer.phar install
|
||||
```
|
||||
|
||||
## Github Actions
|
||||
|
||||
We automatically run your pull request through Github Actions against supported
|
||||
PHP versions. If you break the tests, we cannot merge your code, so please make
|
||||
sure that your code is working before opening up a Pull-Request.
|
||||
|
||||
## Getting merged
|
||||
|
||||
Please allow us time to review your pull requests. We will give our best to review
|
||||
everything as fast as possible, but cannot always live up to our own expectations.
|
||||
|
||||
Thank you very much again for your contribution!
|
19
vendor/doctrine/collections/LICENSE
vendored
Normal file
19
vendor/doctrine/collections/LICENSE
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2006-2013 Doctrine Project
|
||||
|
||||
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.
|
6
vendor/doctrine/collections/README.md
vendored
Normal file
6
vendor/doctrine/collections/README.md
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
# Doctrine Collections
|
||||
|
||||
[](https://github.com/doctrine/collections/actions)
|
||||
[](https://codecov.io/gh/doctrine/collections/branch/2.0.x)
|
||||
|
||||
Collections Abstraction library
|
87
vendor/doctrine/collections/UPGRADE.md
vendored
Normal file
87
vendor/doctrine/collections/UPGRADE.md
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
Note about upgrading: Doctrine uses static and runtime mechanisms to raise
|
||||
awareness about deprecated code.
|
||||
|
||||
- Use of `@deprecated` docblock that is detected by IDEs (like PHPStorm) or
|
||||
Static Analysis tools (like Psalm, phpstan)
|
||||
- Use of our low-overhead runtime deprecation API, details:
|
||||
https://github.com/doctrine/deprecations/
|
||||
|
||||
# Upgrade to 2.0
|
||||
|
||||
## BC breaking changes
|
||||
|
||||
Native parameter types were added. Native return types will be added in 3.0.x
|
||||
As a consequence, some signatures were changed and will have to be adjusted in sub-classes.
|
||||
|
||||
Note that in order to keep compatibility with both 1.x and 2.x versions,
|
||||
extending code would have to omit the added parameter types.
|
||||
This would only work in PHP 7.2+ which is the first version featuring
|
||||
[parameter widening](https://wiki.php.net/rfc/parameter-no-type-variance).
|
||||
It is also recommended to add return types according to the tables below
|
||||
|
||||
You can find a list of major changes to public API below.
|
||||
|
||||
### Doctrine\Common\Collections\Collection
|
||||
|
||||
| 1.0.x | 3.0.x |
|
||||
|---------------------------------:|:-------------------------------------------------|
|
||||
| `add($element)` | `add(mixed $element): void` |
|
||||
| `clear()` | `clear(): void` |
|
||||
| `contains($element)` | `contains(mixed $element): bool` |
|
||||
| `isEmpty()` | `isEmpty(): bool` |
|
||||
| `removeElement($element)` | `removeElement(mixed $element): bool` |
|
||||
| `containsKey($key)` | `containsKey(string\|int $key): bool` |
|
||||
| `get()` | `get(string\|int $key): mixed` |
|
||||
| `getKeys()` | `getKeys(): array` |
|
||||
| `getValues()` | `getValues(): array` |
|
||||
| `set($key, $value)` | `set(string\|int $key, $value): void` |
|
||||
| `toArray()` | `toArray(): array` |
|
||||
| `first()` | `first(): mixed` |
|
||||
| `last()` | `last(): mixed` |
|
||||
| `key()` | `key(): int\|string\|null` |
|
||||
| `current()` | `current(): mixed` |
|
||||
| `next()` | `next(): mixed` |
|
||||
| `exists(Closure $p)` | `exists(Closure $p): bool` |
|
||||
| `filter(Closure $p)` | `filter(Closure $p): self` |
|
||||
| `forAll(Closure $p)` | `forAll(Closure $p): bool` |
|
||||
| `map(Closure $func)` | `map(Closure $func): self` |
|
||||
| `partition(Closure $p)` | `partition(Closure $p): array` |
|
||||
| `indexOf($element)` | `indexOf(mixed $element): int\|string\|false` |
|
||||
| `slice($offset, $length = null)` | `slice(int $offset, ?int $length = null): array` |
|
||||
| `count()` | `count(): int` |
|
||||
| `getIterator()` | `getIterator(): \Traversable` |
|
||||
| `offsetSet($offset, $value)` | `offsetSet(mixed $offset, mixed $value): void` |
|
||||
| `offsetUnset($offset)` | `offsetUnset(mixed $offset): void` |
|
||||
| `offsetExists($offset)` | `offsetExists(mixed $offset): bool` |
|
||||
|
||||
### Doctrine\Common\Collections\AbstractLazyCollection
|
||||
|
||||
| 1.0.x | 3.0.x |
|
||||
|------------------:|:------------------------|
|
||||
| `isInitialized()` | `isInitialized(): bool` |
|
||||
| `initialize()` | `initialize(): void` |
|
||||
| `doInitialize()` | `doInitialize(): void` |
|
||||
|
||||
### Doctrine\Common\Collections\ArrayCollection
|
||||
|
||||
| 1.0.x | 3.0.x |
|
||||
|------------------------------:|:--------------------------------------|
|
||||
| `createFrom(array $elements)` | `createFrom(array $elements): static` |
|
||||
| `__toString()` | `__toString(): string` |
|
||||
|
||||
### Doctrine\Common\Collections\Criteria
|
||||
|
||||
| 1.0.x | 3.0.x |
|
||||
|------------------------------------------:|:--------------------------------------------|
|
||||
| `where(Expression $expression): self` | `where(Expression $expression): static` |
|
||||
| `andWhere(Expression $expression): self` | `andWhere(Expression $expression): static` |
|
||||
| `orWhere(Expression $expression): self` | `orWhere(Expression $expression): static` |
|
||||
| `orderBy(array $orderings): self` | `orderBy(array $orderings): static` |
|
||||
| `setFirstResult(?int $firstResult): self` | `setFirstResult(?int $firstResult): static` |
|
||||
| `setMaxResult(?int $maxResults): self` | `setMaxResults(?int $maxResults): static` |
|
||||
|
||||
### Doctrine\Common\Collections\Selectable
|
||||
|
||||
| 1.0.x | 3.0.x |
|
||||
|-------------------------------:|:-------------------------------------------|
|
||||
| `matching(Criteria $criteria)` | `matching(Criteria $criteria): Collection` |
|
63
vendor/doctrine/collections/composer.json
vendored
Normal file
63
vendor/doctrine/collections/composer.json
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
{
|
||||
"name": "doctrine/collections",
|
||||
"description": "PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.",
|
||||
"license": "MIT",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"php",
|
||||
"collections",
|
||||
"array",
|
||||
"iterators"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Guilherme Blanco",
|
||||
"email": "guilhermeblanco@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Roman Borschel",
|
||||
"email": "roman@code-factory.org"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin Eberlei",
|
||||
"email": "kontakt@beberlei.de"
|
||||
},
|
||||
{
|
||||
"name": "Jonathan Wage",
|
||||
"email": "jonwage@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"email": "schmittjoh@gmail.com"
|
||||
}
|
||||
],
|
||||
"homepage": "https://www.doctrine-project.org/projects/collections.html",
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"doctrine/deprecations": "^1"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-json": "*",
|
||||
"doctrine/coding-standard": "^10.0",
|
||||
"phpstan/phpstan": "^1.8",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"vimeo/psalm": "^4.22"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Common\\Collections\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Tests\\": "tests"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"composer/package-versions-deprecated": true,
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||
}
|
||||
}
|
||||
}
|
26
vendor/doctrine/collections/docs/en/derived-collections.rst
vendored
Normal file
26
vendor/doctrine/collections/docs/en/derived-collections.rst
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
Derived Collections
|
||||
===================
|
||||
|
||||
You can create custom collection classes by extending the
|
||||
``Doctrine\Common\Collections\ArrayCollection`` class. If the
|
||||
``__construct`` semantics are different from the default ``ArrayCollection``
|
||||
you can override the ``createFrom`` method:
|
||||
|
||||
.. code-block:: php
|
||||
final class DerivedArrayCollection extends ArrayCollection
|
||||
{
|
||||
/** @var \stdClass */
|
||||
private $foo;
|
||||
|
||||
public function __construct(\stdClass $foo, array $elements = [])
|
||||
{
|
||||
$this->foo = $foo;
|
||||
|
||||
parent::__construct($elements);
|
||||
}
|
||||
|
||||
protected function createFrom(array $elements) : self
|
||||
{
|
||||
return new static($this->foo, $elements);
|
||||
}
|
||||
}
|
185
vendor/doctrine/collections/docs/en/expression-builder.rst
vendored
Normal file
185
vendor/doctrine/collections/docs/en/expression-builder.rst
vendored
Normal file
@ -0,0 +1,185 @@
|
||||
Expression Builder
|
||||
==================
|
||||
|
||||
The Expression Builder is a convenient fluent interface for
|
||||
building expressions to be used with the ``Doctrine\Common\Collections\Criteria``
|
||||
class:
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$criteria = new Criteria();
|
||||
$criteria->where($expressionBuilder->eq('name', 'jwage'));
|
||||
$criteria->orWhere($expressionBuilder->eq('name', 'romanb'));
|
||||
|
||||
$collection->matching($criteria);
|
||||
|
||||
The ``ExpressionBuilder`` has the following API:
|
||||
|
||||
andX
|
||||
----
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->andX(
|
||||
$expressionBuilder->eq('foo', 1),
|
||||
$expressionBuilder->eq('bar', 1)
|
||||
);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
orX
|
||||
---
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->orX(
|
||||
$expressionBuilder->eq('foo', 1),
|
||||
$expressionBuilder->eq('bar', 1)
|
||||
);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
not
|
||||
---
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->not(
|
||||
$expressionBuilder->eq('foo', 1)
|
||||
);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
eq
|
||||
---
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->eq('foo', 1);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
gt
|
||||
---
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->gt('foo', 1);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
lt
|
||||
---
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->lt('foo', 1);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
gte
|
||||
---
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->gte('foo', 1);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
lte
|
||||
---
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->lte('foo', 1);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
neq
|
||||
---
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->neq('foo', 1);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
isNull
|
||||
------
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->isNull('foo');
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
in
|
||||
---
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->in('foo', ['value1', 'value2']);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
notIn
|
||||
-----
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->notIn('foo', ['value1', 'value2']);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
contains
|
||||
--------
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->contains('foo', 'value1');
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
memberOf
|
||||
--------
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->memberOf('foo', ['value1', 'value2']);
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
startsWith
|
||||
----------
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->startsWith('foo', 'hello');
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
||||
|
||||
endsWith
|
||||
--------
|
||||
|
||||
.. code-block:: php
|
||||
$expressionBuilder = Criteria::expr();
|
||||
|
||||
$expression = $expressionBuilder->endsWith('foo', 'world');
|
||||
|
||||
$collection->matching(new Criteria($expression));
|
115
vendor/doctrine/collections/docs/en/expressions.rst
vendored
Normal file
115
vendor/doctrine/collections/docs/en/expressions.rst
vendored
Normal file
@ -0,0 +1,115 @@
|
||||
Expressions
|
||||
===========
|
||||
|
||||
The ``Doctrine\Common\Collections\Expr\Comparison`` class
|
||||
can be used to create comparison expressions to be used with the
|
||||
``Doctrine\Common\Collections\Criteria`` class. It has the
|
||||
following operator constants:
|
||||
|
||||
- ``Comparison::EQ``
|
||||
- ``Comparison::NEQ``
|
||||
- ``Comparison::LT``
|
||||
- ``Comparison::LTE``
|
||||
- ``Comparison::GT``
|
||||
- ``Comparison::GTE``
|
||||
- ``Comparison::IS``
|
||||
- ``Comparison::IN``
|
||||
- ``Comparison::NIN``
|
||||
- ``Comparison::CONTAINS``
|
||||
- ``Comparison::MEMBER_OF``
|
||||
- ``Comparison::STARTS_WITH``
|
||||
- ``Comparison::ENDS_WITH``
|
||||
|
||||
The ``Doctrine\Common\Collections\Expr\CompositeExpression`` class
|
||||
can be used to create composite expressions to be used with the
|
||||
``Doctrine\Common\Collections\Criteria`` class. It has the
|
||||
following operator constants:
|
||||
|
||||
- ``CompositeExpression::TYPE_AND``
|
||||
- ``CompositeExpression::TYPE_OR``
|
||||
- ``CompositeExpression::TYPE_NOT``
|
||||
|
||||
When using the ``TYPE_OR`` and ``TYPE_AND`` operators the
|
||||
``CompositeExpression`` accepts multiple expressions as parameter
|
||||
but only one expression can be provided when using the ``NOT`` operator.
|
||||
|
||||
The ``Doctrine\Common\Collections\Criteria`` class has the following
|
||||
API to be used with expressions:
|
||||
|
||||
where
|
||||
-----
|
||||
|
||||
Sets the where expression to evaluate when this Criteria is searched for.
|
||||
|
||||
.. code-block:: php
|
||||
$expr = new Comparison('key', Comparison::EQ, 'value');
|
||||
|
||||
$criteria->where($expr);
|
||||
|
||||
andWhere
|
||||
--------
|
||||
|
||||
Appends the where expression to evaluate when this Criteria is searched for
|
||||
using an AND with previous expression.
|
||||
|
||||
.. code-block:: php
|
||||
$expr = new Comparison('key', Comparison::EQ, 'value');
|
||||
|
||||
$criteria->andWhere($expr);
|
||||
|
||||
orWhere
|
||||
-------
|
||||
|
||||
Appends the where expression to evaluate when this Criteria is searched for
|
||||
using an OR with previous expression.
|
||||
|
||||
.. code-block:: php
|
||||
$expr1 = new Comparison('key', Comparison::EQ, 'value1');
|
||||
$expr2 = new Comparison('key', Comparison::EQ, 'value2');
|
||||
|
||||
$criteria->where($expr1);
|
||||
$criteria->orWhere($expr2);
|
||||
|
||||
orderBy
|
||||
-------
|
||||
|
||||
Sets the ordering of the result of this Criteria.
|
||||
|
||||
.. code-block:: php
|
||||
$criteria->orderBy(['name' => Criteria::ASC]);
|
||||
|
||||
setFirstResult
|
||||
--------------
|
||||
|
||||
Set the number of first result that this Criteria should return.
|
||||
|
||||
.. code-block:: php
|
||||
$criteria->setFirstResult(0);
|
||||
|
||||
getFirstResult
|
||||
--------------
|
||||
|
||||
Gets the current first result option of this Criteria.
|
||||
|
||||
.. code-block:: php
|
||||
$criteria->setFirstResult(10);
|
||||
|
||||
echo $criteria->getFirstResult(); // 10
|
||||
|
||||
setMaxResults
|
||||
-------------
|
||||
|
||||
Sets the max results that this Criteria should return.
|
||||
|
||||
.. code-block:: php
|
||||
$criteria->setMaxResults(20);
|
||||
|
||||
getMaxResults
|
||||
-------------
|
||||
|
||||
Gets the current max results option of this Criteria.
|
||||
|
||||
.. code-block:: php
|
||||
$criteria->setMaxResults(20);
|
||||
|
||||
echo $criteria->getMaxResults(); // 20
|
357
vendor/doctrine/collections/docs/en/index.rst
vendored
Normal file
357
vendor/doctrine/collections/docs/en/index.rst
vendored
Normal file
@ -0,0 +1,357 @@
|
||||
Introduction
|
||||
============
|
||||
|
||||
Doctrine Collections is a library that contains classes for working with
|
||||
arrays of data. Here is an example using the simple
|
||||
``Doctrine\Common\Collections\ArrayCollection`` class:
|
||||
|
||||
.. code-block:: php
|
||||
<?php
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$filteredCollection = $collection->filter(function($element) {
|
||||
return $element > 1;
|
||||
}); // [2, 3]
|
||||
|
||||
Collection Methods
|
||||
==================
|
||||
|
||||
Doctrine Collections provides an interface named ``Doctrine\Common\Collections\Collection``
|
||||
that resembles the nature of a regular PHP array. That is,
|
||||
it is essentially an **ordered map** that can also be used
|
||||
like a list.
|
||||
|
||||
A Collection has an internal iterator just like a PHP array. In addition,
|
||||
a Collection can be iterated with external iterators, which is preferable.
|
||||
To use an external iterator simply use the foreach language construct to
|
||||
iterate over the collection, which calls ``getIterator()`` internally, or
|
||||
explicitly retrieve an iterator though ``getIterator()`` which can then be
|
||||
used to iterate over the collection. You can not rely on the internal iterator
|
||||
of the collection being at a certain position unless you explicitly positioned it before.
|
||||
|
||||
Methods that do not alter the collection or have template types
|
||||
appearing in invariant or contravariant positions are not directly
|
||||
defined in ``Doctrine\Common\Collections\Collection``, but are inherited
|
||||
from the ``Doctrine\Common\Collections\ReadableCollection`` interface.
|
||||
|
||||
The methods available on the interface are:
|
||||
|
||||
add
|
||||
---
|
||||
|
||||
Adds an element at the end of the collection.
|
||||
|
||||
.. code-block:: php
|
||||
$collection->add('test');
|
||||
|
||||
clear
|
||||
-----
|
||||
|
||||
Clears the collection, removing all elements.
|
||||
|
||||
.. code-block:: php
|
||||
$collection->clear();
|
||||
|
||||
contains
|
||||
--------
|
||||
|
||||
Checks whether an element is contained in the collection. This is an O(n) operation, where n is the size of the collection.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new Collection(['test']);
|
||||
|
||||
$contains = $collection->contains('test'); // true
|
||||
|
||||
containsKey
|
||||
-----------
|
||||
|
||||
Checks whether the collection contains an element with the specified key/index.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new Collection(['test' => true]);
|
||||
|
||||
$contains = $collection->containsKey('test'); // true
|
||||
|
||||
current
|
||||
-------
|
||||
|
||||
Gets the element of the collection at the current iterator position.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new Collection(['first', 'second', 'third']);
|
||||
|
||||
$current = $collection->current(); // first
|
||||
|
||||
get
|
||||
---
|
||||
|
||||
Gets the element at the specified key/index.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new Collection([
|
||||
'key' => 'value',
|
||||
]);
|
||||
|
||||
$value = $collection->get('key'); // value
|
||||
|
||||
getKeys
|
||||
-------
|
||||
|
||||
Gets all keys/indices of the collection.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new Collection(['a', 'b', 'c']);
|
||||
|
||||
$keys = $collection->getKeys(); // [0, 1, 2]
|
||||
|
||||
getValues
|
||||
---------
|
||||
|
||||
Gets all values of the collection.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new Collection([
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
'key3' => 'value3',
|
||||
]);
|
||||
|
||||
$values = $collection->getValues(); // ['value1', 'value2', 'value3']
|
||||
|
||||
isEmpty
|
||||
-------
|
||||
|
||||
Checks whether the collection is empty (contains no elements).
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new Collection(['a', 'b', 'c']);
|
||||
|
||||
$isEmpty = $collection->isEmpty(); // false
|
||||
|
||||
first
|
||||
-----
|
||||
|
||||
Sets the internal iterator to the first element in the collection and returns this element.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new Collection(['first', 'second', 'third']);
|
||||
|
||||
$first = $collection->first(); // first
|
||||
|
||||
exists
|
||||
------
|
||||
|
||||
Tests for the existence of an element that satisfies the given predicate.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new Collection(['first', 'second', 'third']);
|
||||
|
||||
$exists = $collection->exists(function($key, $value) {
|
||||
return $value === 'first';
|
||||
}); // true
|
||||
|
||||
findFirst
|
||||
---------
|
||||
|
||||
Returns the first element of this collection that satisfies the given predicate.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new Collection([1, 2, 3, 2, 1]);
|
||||
|
||||
$one = $collection->findFirst(function(int $key, int $value): bool {
|
||||
return $value > 2 && $key > 1;
|
||||
}); // 3
|
||||
|
||||
filter
|
||||
------
|
||||
|
||||
Returns all the elements of this collection for which your callback function returns `true`.
|
||||
The order and keys of the elements are preserved.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$filteredCollection = $collection->filter(function($element) {
|
||||
return $element > 1;
|
||||
}); // [2, 3]
|
||||
|
||||
forAll
|
||||
------
|
||||
|
||||
Tests whether the given predicate holds for all elements of this collection.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$forAll = $collection->forAll(function($key, $value) {
|
||||
return $value > 1;
|
||||
}); // false
|
||||
|
||||
indexOf
|
||||
-------
|
||||
|
||||
Gets the index/key of a given element. The comparison of two elements is strict, that means not only the value but also the type must match. For objects this means reference equality.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$indexOf = $collection->indexOf(3); // 2
|
||||
|
||||
key
|
||||
---
|
||||
|
||||
Gets the key/index of the element at the current iterator position.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$collection->next();
|
||||
|
||||
$key = $collection->key(); // 1
|
||||
|
||||
last
|
||||
----
|
||||
|
||||
Sets the internal iterator to the last element in the collection and returns this element.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$last = $collection->last(); // 3
|
||||
|
||||
map
|
||||
---
|
||||
|
||||
Applies the given function to each element in the collection and returns a new collection with the elements returned by the function.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$mappedCollection = $collection->map(function($value) {
|
||||
return $value + 1;
|
||||
}); // [2, 3, 4]
|
||||
|
||||
reduce
|
||||
------
|
||||
|
||||
Applies iteratively the given function to each element in the collection, so as to reduce the collection to a single value.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$reduce = $collection->reduce(function(int $accumulator, int $value): int {
|
||||
return $accumulator + $value;
|
||||
}, 0); // 6
|
||||
|
||||
next
|
||||
----
|
||||
|
||||
Moves the internal iterator position to the next element and returns this element.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$next = $collection->next(); // 2
|
||||
|
||||
partition
|
||||
---------
|
||||
|
||||
Partitions this collection in two collections according to a predicate. Keys are preserved in the resulting collections.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$mappedCollection = $collection->partition(function($key, $value) {
|
||||
return $value > 1
|
||||
}); // [[2, 3], [1]]
|
||||
|
||||
remove
|
||||
------
|
||||
|
||||
Removes the element at the specified index from the collection.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$collection->remove(0); // [2, 3]
|
||||
|
||||
removeElement
|
||||
-------------
|
||||
|
||||
Removes the specified element from the collection, if it is found.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
|
||||
$collection->removeElement(3); // [1, 2]
|
||||
|
||||
set
|
||||
---
|
||||
|
||||
Sets an element in the collection at the specified key/index.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection();
|
||||
|
||||
$collection->set('name', 'jwage');
|
||||
|
||||
slice
|
||||
-----
|
||||
|
||||
Extracts a slice of $length elements starting at position $offset from the Collection. If $length is null it returns all elements from $offset to the end of the Collection. Keys have to be preserved by this method. Calling this method will only return the selected slice and NOT change the elements contained in the collection slice is called on.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([0, 1, 2, 3, 4, 5]);
|
||||
|
||||
$slice = $collection->slice(1, 2); // [1, 2]
|
||||
|
||||
toArray
|
||||
-------
|
||||
|
||||
Gets a native PHP array representation of the collection.
|
||||
|
||||
.. code-block:: php
|
||||
$collection = new ArrayCollection([0, 1, 2, 3, 4, 5]);
|
||||
|
||||
$array = $collection->toArray(); // [0, 1, 2, 3, 4, 5]
|
||||
|
||||
Selectable Methods
|
||||
==================
|
||||
|
||||
Some Doctrine Collections, like ``Doctrine\Common\Collections\ArrayCollection``,
|
||||
implement an interface named ``Doctrine\Common\Collections\Selectable``
|
||||
that offers the usage of a powerful expressions API, where conditions
|
||||
can be applied to a collection to get a result with matching elements
|
||||
only.
|
||||
|
||||
matching
|
||||
--------
|
||||
|
||||
Selects all elements from a selectable that match the expression and
|
||||
returns a new collection containing these elements and preserved keys.
|
||||
|
||||
.. code-block:: php
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
|
||||
$collection = new ArrayCollection([
|
||||
'wage' => [
|
||||
'name' => 'jwage',
|
||||
],
|
||||
'roman' => [
|
||||
'name' => 'romanb',
|
||||
],
|
||||
]);
|
||||
|
||||
$expr = new Comparison('name', '=', 'jwage');
|
||||
|
||||
$criteria = new Criteria();
|
||||
|
||||
$criteria->where($expr);
|
||||
|
||||
$matchingCollection = $collection->matching($criteria); // [ 'wage' => [ 'name' => 'jwage' ]]
|
||||
|
||||
You can read more about expressions :ref:`here <expressions>`.
|
26
vendor/doctrine/collections/docs/en/lazy-collections.rst
vendored
Normal file
26
vendor/doctrine/collections/docs/en/lazy-collections.rst
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
Lazy Collections
|
||||
================
|
||||
|
||||
To create a lazy collection you can extend the
|
||||
``Doctrine\Common\Collections\AbstractLazyCollection`` class
|
||||
and define the ``doInitialize`` method. Here is an example where
|
||||
we lazily query the database for a collection of user records:
|
||||
|
||||
.. code-block:: php
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
class UsersLazyCollection extends AbstractLazyCollection
|
||||
{
|
||||
/** @var Connection */
|
||||
private $connection;
|
||||
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
protected function doInitialize() : void
|
||||
{
|
||||
$this->collection = $this->connection->fetchAll('SELECT * FROM users');
|
||||
}
|
||||
}
|
29
vendor/doctrine/collections/docs/en/serialization.rst
vendored
Normal file
29
vendor/doctrine/collections/docs/en/serialization.rst
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
Serialization
|
||||
=============
|
||||
|
||||
Using (un-)serialize() on a collection is not a supported use-case
|
||||
and may break when changes on the collection's internals happen in the future.
|
||||
If a collection needs to be serialized, use ``toArray()`` and reconstruct
|
||||
the collection manually.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$collection = new ArrayCollection([1, 2, 3]);
|
||||
$serialized = serialize($collection->toArray());
|
||||
|
||||
A reconstruction is also necessary when the collection contains objects with
|
||||
infinite recursion of dependencies like in this ``json_serialize()`` example:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$foo = new Foo();
|
||||
$bar = new Bar();
|
||||
|
||||
$foo->setBar($bar);
|
||||
$bar->setFoo($foo);
|
||||
|
||||
$collection = new ArrayCollection([$foo]);
|
||||
$json = json_serialize($collection->toArray()); // recursion detected
|
||||
|
||||
Serializer libraries can be used to create the serialization-output to prevent
|
||||
errors.
|
9
vendor/doctrine/collections/docs/en/sidebar.rst
vendored
Normal file
9
vendor/doctrine/collections/docs/en/sidebar.rst
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
.. toctree::
|
||||
:depth: 3
|
||||
|
||||
index
|
||||
expressions
|
||||
expression-builder
|
||||
derived-collections
|
||||
lazy-collections
|
||||
serialization
|
426
vendor/doctrine/collections/src/AbstractLazyCollection.php
vendored
Normal file
426
vendor/doctrine/collections/src/AbstractLazyCollection.php
vendored
Normal file
@ -0,0 +1,426 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use Closure;
|
||||
use LogicException;
|
||||
use ReturnTypeWillChange;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Lazy collection that is backed by a concrete collection
|
||||
*
|
||||
* @psalm-template TKey of array-key
|
||||
* @psalm-template T
|
||||
* @template-implements Collection<TKey,T>
|
||||
*/
|
||||
abstract class AbstractLazyCollection implements Collection
|
||||
{
|
||||
/**
|
||||
* The backed collection to use
|
||||
*
|
||||
* @psalm-var Collection<TKey,T>|null
|
||||
* @var Collection<mixed>|null
|
||||
*/
|
||||
protected Collection|null $collection;
|
||||
|
||||
protected bool $initialized = false;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function add(mixed $element)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$this->collection->add($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->initialize();
|
||||
$this->collection->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @template TMaybeContained
|
||||
*/
|
||||
public function contains(mixed $element)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->contains($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function remove(string|int $key)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->remove($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function removeElement(mixed $element)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->removeElement($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function containsKey(string|int $key)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->containsKey($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get(string|int $key)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getKeys()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->getKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->getValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set(string|int $key, mixed $value)
|
||||
{
|
||||
$this->initialize();
|
||||
$this->collection->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function first()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function last()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->last();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->key();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->current();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->next();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function exists(Closure $p)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->exists($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findFirst(Closure $p)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->findFirst($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-param Closure(T, TKey):bool $p
|
||||
*
|
||||
* @return ReadableCollection<mixed>
|
||||
* @psalm-return ReadableCollection<TKey, T>
|
||||
*/
|
||||
public function filter(Closure $p)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->filter($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function forAll(Closure $p)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->forAll($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @psalm-param Closure(T):U $func
|
||||
*
|
||||
* @return ReadableCollection<mixed>
|
||||
* @psalm-return ReadableCollection<TKey, U>
|
||||
*
|
||||
* @psalm-template U
|
||||
*/
|
||||
public function map(Closure $func)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->map($func);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function reduce(Closure $func, mixed $initial = null)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->reduce($func, $initial);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function partition(Closure $p)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->partition($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @template TMaybeContained
|
||||
*/
|
||||
public function indexOf(mixed $element)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->indexOf($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function slice(int $offset, int|null $length = null)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->slice($offset, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return Traversable<int|string, mixed>
|
||||
* @psalm-return Traversable<TKey,T>
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->getIterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param TKey $offset
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetExists(mixed $offset)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->offsetExists($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param TKey $offset
|
||||
*
|
||||
* @return T|null
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetGet(mixed $offset)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->collection->offsetGet($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param TKey|null $offset
|
||||
* @param T $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetSet(mixed $offset, mixed $value)
|
||||
{
|
||||
$this->initialize();
|
||||
$this->collection->offsetSet($offset, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TKey $offset
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetUnset(mixed $offset)
|
||||
{
|
||||
$this->initialize();
|
||||
$this->collection->offsetUnset($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the lazy collection already initialized?
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @psalm-assert-if-true Collection<TKey,T> $this->collection
|
||||
*/
|
||||
public function isInitialized()
|
||||
{
|
||||
return $this->initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the collection
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @psalm-assert Collection<TKey,T> $this->collection
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
if ($this->initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->doInitialize();
|
||||
$this->initialized = true;
|
||||
|
||||
if ($this->collection === null) {
|
||||
throw new LogicException('You must initialize the collection property in the doInitialize() method.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the initialization logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function doInitialize();
|
||||
}
|
488
vendor/doctrine/collections/src/ArrayCollection.php
vendored
Normal file
488
vendor/doctrine/collections/src/ArrayCollection.php
vendored
Normal file
@ -0,0 +1,488 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use ArrayIterator;
|
||||
use Closure;
|
||||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
|
||||
use ReturnTypeWillChange;
|
||||
use Stringable;
|
||||
use Traversable;
|
||||
|
||||
use function array_filter;
|
||||
use function array_key_exists;
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
use function array_reduce;
|
||||
use function array_reverse;
|
||||
use function array_search;
|
||||
use function array_slice;
|
||||
use function array_values;
|
||||
use function count;
|
||||
use function current;
|
||||
use function end;
|
||||
use function in_array;
|
||||
use function key;
|
||||
use function next;
|
||||
use function reset;
|
||||
use function spl_object_hash;
|
||||
use function uasort;
|
||||
|
||||
use const ARRAY_FILTER_USE_BOTH;
|
||||
|
||||
/**
|
||||
* An ArrayCollection is a Collection implementation that wraps a regular PHP array.
|
||||
*
|
||||
* Warning: Using (un-)serialize() on a collection is not a supported use-case
|
||||
* and may break when we change the internals in the future. If you need to
|
||||
* serialize a collection use {@link toArray()} and reconstruct the collection
|
||||
* manually.
|
||||
*
|
||||
* @psalm-template TKey of array-key
|
||||
* @psalm-template T
|
||||
* @template-implements Collection<TKey,T>
|
||||
* @template-implements Selectable<TKey,T>
|
||||
* @psalm-consistent-constructor
|
||||
*/
|
||||
class ArrayCollection implements Collection, Selectable, Stringable
|
||||
{
|
||||
/**
|
||||
* An array containing the entries of this collection.
|
||||
*
|
||||
* @psalm-var array<TKey,T>
|
||||
* @var mixed[]
|
||||
*/
|
||||
private array $elements = [];
|
||||
|
||||
/**
|
||||
* Initializes a new ArrayCollection.
|
||||
*
|
||||
* @param array $elements
|
||||
* @psalm-param array<TKey,T> $elements
|
||||
*/
|
||||
public function __construct(array $elements = [])
|
||||
{
|
||||
$this->elements = $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function first()
|
||||
{
|
||||
return reset($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance from the specified elements.
|
||||
*
|
||||
* This method is provided for derived classes to specify how a new
|
||||
* instance should be created when constructor semantics have changed.
|
||||
*
|
||||
* @param array $elements Elements.
|
||||
* @psalm-param array<K,V> $elements
|
||||
*
|
||||
* @return static
|
||||
* @psalm-return static<K,V>
|
||||
*
|
||||
* @psalm-template K of array-key
|
||||
* @psalm-template V
|
||||
*/
|
||||
protected function createFrom(array $elements)
|
||||
{
|
||||
return new static($elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function last()
|
||||
{
|
||||
return end($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return key($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
return next($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return current($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function remove(string|int $key)
|
||||
{
|
||||
if (! isset($this->elements[$key]) && ! array_key_exists($key, $this->elements)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$removed = $this->elements[$key];
|
||||
unset($this->elements[$key]);
|
||||
|
||||
return $removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function removeElement(mixed $element)
|
||||
{
|
||||
$key = array_search($element, $this->elements, true);
|
||||
|
||||
if ($key === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unset($this->elements[$key]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by interface ArrayAccess.
|
||||
*
|
||||
* @param TKey $offset
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetExists(mixed $offset)
|
||||
{
|
||||
return $this->containsKey($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by interface ArrayAccess.
|
||||
*
|
||||
* @param TKey $offset
|
||||
*
|
||||
* @return T|null
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetGet(mixed $offset)
|
||||
{
|
||||
return $this->get($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by interface ArrayAccess.
|
||||
*
|
||||
* @param TKey|null $offset
|
||||
* @param T $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetSet(mixed $offset, mixed $value)
|
||||
{
|
||||
if ($offset === null) {
|
||||
$this->add($value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set($offset, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by interface ArrayAccess.
|
||||
*
|
||||
* @param TKey $offset
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetUnset(mixed $offset)
|
||||
{
|
||||
$this->remove($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function containsKey(string|int $key)
|
||||
{
|
||||
return isset($this->elements[$key]) || array_key_exists($key, $this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @template TMaybeContained
|
||||
*/
|
||||
public function contains(mixed $element)
|
||||
{
|
||||
return in_array($element, $this->elements, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function exists(Closure $p)
|
||||
{
|
||||
foreach ($this->elements as $key => $element) {
|
||||
if ($p($key, $element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @psalm-param TMaybeContained $element
|
||||
*
|
||||
* @return int|string|false
|
||||
* @psalm-return (TMaybeContained is T ? TKey|false : false)
|
||||
*
|
||||
* @template TMaybeContained
|
||||
*/
|
||||
public function indexOf($element)
|
||||
{
|
||||
return array_search($element, $this->elements, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get(string|int $key)
|
||||
{
|
||||
return $this->elements[$key] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getKeys()
|
||||
{
|
||||
return array_keys($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
return array_values($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return int<0, max>
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return count($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set(string|int $key, mixed $value)
|
||||
{
|
||||
$this->elements[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @psalm-suppress InvalidPropertyAssignmentValue
|
||||
*
|
||||
* This breaks assumptions about the template type, but it would
|
||||
* be a backwards-incompatible change to remove this method
|
||||
*/
|
||||
public function add(mixed $element)
|
||||
{
|
||||
$this->elements[] = $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return empty($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return Traversable<int|string, mixed>
|
||||
* @psalm-return Traversable<TKey, T>
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @psalm-param Closure(T):U $func
|
||||
*
|
||||
* @return static
|
||||
* @psalm-return static<TKey, U>
|
||||
*
|
||||
* @psalm-template U
|
||||
*/
|
||||
public function map(Closure $func)
|
||||
{
|
||||
return $this->createFrom(array_map($func, $this->elements));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function reduce(Closure $func, $initial = null)
|
||||
{
|
||||
return array_reduce($this->elements, $func, $initial);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return static
|
||||
* @psalm-return static<TKey,T>
|
||||
*/
|
||||
public function filter(Closure $p)
|
||||
{
|
||||
return $this->createFrom(array_filter($this->elements, $p, ARRAY_FILTER_USE_BOTH));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findFirst(Closure $p)
|
||||
{
|
||||
foreach ($this->elements as $key => $element) {
|
||||
if ($p($key, $element)) {
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function forAll(Closure $p)
|
||||
{
|
||||
foreach ($this->elements as $key => $element) {
|
||||
if (! $p($key, $element)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function partition(Closure $p)
|
||||
{
|
||||
$matches = $noMatches = [];
|
||||
|
||||
foreach ($this->elements as $key => $element) {
|
||||
if ($p($key, $element)) {
|
||||
$matches[$key] = $element;
|
||||
} else {
|
||||
$noMatches[$key] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
return [$this->createFrom($matches), $this->createFrom($noMatches)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return self::class . '@' . spl_object_hash($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->elements = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function slice(int $offset, int|null $length = null)
|
||||
{
|
||||
return array_slice($this->elements, $offset, $length, true);
|
||||
}
|
||||
|
||||
/** @psalm-return Collection<TKey, T>&Selectable<TKey,T> */
|
||||
public function matching(Criteria $criteria)
|
||||
{
|
||||
$expr = $criteria->getWhereExpression();
|
||||
$filtered = $this->elements;
|
||||
|
||||
if ($expr) {
|
||||
$visitor = new ClosureExpressionVisitor();
|
||||
$filter = $visitor->dispatch($expr);
|
||||
$filtered = array_filter($filtered, $filter);
|
||||
}
|
||||
|
||||
$orderings = $criteria->getOrderings();
|
||||
|
||||
if ($orderings) {
|
||||
$next = null;
|
||||
foreach (array_reverse($orderings) as $field => $ordering) {
|
||||
$next = ClosureExpressionVisitor::sortByField($field, $ordering === Criteria::DESC ? -1 : 1, $next);
|
||||
}
|
||||
|
||||
uasort($filtered, $next);
|
||||
}
|
||||
|
||||
$offset = $criteria->getFirstResult();
|
||||
$length = $criteria->getMaxResults();
|
||||
|
||||
if ($offset || $length) {
|
||||
$filtered = array_slice($filtered, (int) $offset, $length, true);
|
||||
}
|
||||
|
||||
return $this->createFrom($filtered);
|
||||
}
|
||||
}
|
82
vendor/doctrine/collections/src/Collection.php
vendored
Normal file
82
vendor/doctrine/collections/src/Collection.php
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use ArrayAccess;
|
||||
|
||||
/**
|
||||
* The missing (SPL) Collection/Array/OrderedMap interface.
|
||||
*
|
||||
* A Collection resembles the nature of a regular PHP array. That is,
|
||||
* it is essentially an <b>ordered map</b> that can also be used
|
||||
* like a list.
|
||||
*
|
||||
* A Collection has an internal iterator just like a PHP array. In addition,
|
||||
* a Collection can be iterated with external iterators, which is preferable.
|
||||
* To use an external iterator simply use the foreach language construct to
|
||||
* iterate over the collection (which calls {@link getIterator()} internally) or
|
||||
* explicitly retrieve an iterator though {@link getIterator()} which can then be
|
||||
* used to iterate over the collection.
|
||||
* You can not rely on the internal iterator of the collection being at a certain
|
||||
* position unless you explicitly positioned it before. Prefer iteration with
|
||||
* external iterators.
|
||||
*
|
||||
* @psalm-template TKey of array-key
|
||||
* @psalm-template T
|
||||
* @template-extends ReadableCollection<TKey, T>
|
||||
* @template-extends ArrayAccess<TKey, T>
|
||||
*/
|
||||
interface Collection extends ReadableCollection, ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Adds an element at the end of the collection.
|
||||
*
|
||||
* @param mixed $element The element to add.
|
||||
* @psalm-param T $element
|
||||
*
|
||||
* @return void we will require a native return type declaration in 3.0
|
||||
*/
|
||||
public function add(mixed $element);
|
||||
|
||||
/**
|
||||
* Clears the collection, removing all elements.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear();
|
||||
|
||||
/**
|
||||
* Removes the element at the specified index from the collection.
|
||||
*
|
||||
* @param string|int $key The key/index of the element to remove.
|
||||
* @psalm-param TKey $key
|
||||
*
|
||||
* @return mixed The removed element or NULL, if the collection did not contain the element.
|
||||
* @psalm-return T|null
|
||||
*/
|
||||
public function remove(string|int $key);
|
||||
|
||||
/**
|
||||
* Removes the specified element from the collection, if it is found.
|
||||
*
|
||||
* @param mixed $element The element to remove.
|
||||
* @psalm-param T $element
|
||||
*
|
||||
* @return bool TRUE if this collection contained the specified element, FALSE otherwise.
|
||||
*/
|
||||
public function removeElement(mixed $element);
|
||||
|
||||
/**
|
||||
* Sets an element in the collection at the specified key/index.
|
||||
*
|
||||
* @param string|int $key The key/index of the element to set.
|
||||
* @param mixed $value The element to set.
|
||||
* @psalm-param TKey $key
|
||||
* @psalm-param T $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set(string|int $key, mixed $value);
|
||||
}
|
239
vendor/doctrine/collections/src/Criteria.php
vendored
Normal file
239
vendor/doctrine/collections/src/Criteria.php
vendored
Normal file
@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use Doctrine\Common\Collections\Expr\CompositeExpression;
|
||||
use Doctrine\Common\Collections\Expr\Expression;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
use function array_map;
|
||||
use function func_num_args;
|
||||
use function strtoupper;
|
||||
|
||||
/**
|
||||
* Criteria for filtering Selectable collections.
|
||||
*
|
||||
* @psalm-consistent-constructor
|
||||
*/
|
||||
class Criteria
|
||||
{
|
||||
final public const ASC = 'ASC';
|
||||
final public const DESC = 'DESC';
|
||||
|
||||
private static ExpressionBuilder|null $expressionBuilder = null;
|
||||
|
||||
/** @var array<string, string> */
|
||||
private array $orderings = [];
|
||||
|
||||
private int|null $firstResult = null;
|
||||
private int|null $maxResults = null;
|
||||
|
||||
/**
|
||||
* Creates an instance of the class.
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expression builder.
|
||||
*
|
||||
* @return ExpressionBuilder
|
||||
*/
|
||||
public static function expr()
|
||||
{
|
||||
if (self::$expressionBuilder === null) {
|
||||
self::$expressionBuilder = new ExpressionBuilder();
|
||||
}
|
||||
|
||||
return self::$expressionBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new Criteria.
|
||||
*
|
||||
* @param array<string, string>|null $orderings
|
||||
*/
|
||||
public function __construct(
|
||||
private Expression|null $expression = null,
|
||||
array|null $orderings = null,
|
||||
int|null $firstResult = null,
|
||||
int|null $maxResults = null,
|
||||
) {
|
||||
$this->expression = $expression;
|
||||
|
||||
if ($firstResult === null && func_num_args() > 2) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/collections',
|
||||
'https://github.com/doctrine/collections/pull/311',
|
||||
'Passing null as $firstResult to the constructor of %s is deprecated. Pass 0 instead or omit the argument.',
|
||||
self::class,
|
||||
);
|
||||
}
|
||||
|
||||
$this->setFirstResult($firstResult);
|
||||
$this->setMaxResults($maxResults);
|
||||
|
||||
if ($orderings === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->orderBy($orderings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the where expression to evaluate when this Criteria is searched for.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function where(Expression $expression)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the where expression to evaluate when this Criteria is searched for
|
||||
* using an AND with previous expression.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function andWhere(Expression $expression)
|
||||
{
|
||||
if ($this->expression === null) {
|
||||
return $this->where($expression);
|
||||
}
|
||||
|
||||
$this->expression = new CompositeExpression(
|
||||
CompositeExpression::TYPE_AND,
|
||||
[$this->expression, $expression],
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the where expression to evaluate when this Criteria is searched for
|
||||
* using an OR with previous expression.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function orWhere(Expression $expression)
|
||||
{
|
||||
if ($this->expression === null) {
|
||||
return $this->where($expression);
|
||||
}
|
||||
|
||||
$this->expression = new CompositeExpression(
|
||||
CompositeExpression::TYPE_OR,
|
||||
[$this->expression, $expression],
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the expression attached to this Criteria.
|
||||
*
|
||||
* @return Expression|null
|
||||
*/
|
||||
public function getWhereExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current orderings of this Criteria.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getOrderings()
|
||||
{
|
||||
return $this->orderings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ordering of the result of this Criteria.
|
||||
*
|
||||
* Keys are field and values are the order, being either ASC or DESC.
|
||||
*
|
||||
* @see Criteria::ASC
|
||||
* @see Criteria::DESC
|
||||
*
|
||||
* @param array<string, string> $orderings
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function orderBy(array $orderings)
|
||||
{
|
||||
$this->orderings = array_map(
|
||||
static fn (string $ordering): string => strtoupper($ordering) === self::ASC ? self::ASC : self::DESC,
|
||||
$orderings,
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current first result option of this Criteria.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getFirstResult()
|
||||
{
|
||||
return $this->firstResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of first result that this Criteria should return.
|
||||
*
|
||||
* @param int|null $firstResult The value to set.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFirstResult(int|null $firstResult)
|
||||
{
|
||||
if ($firstResult === null) {
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'doctrine/collections',
|
||||
'https://github.com/doctrine/collections/pull/311',
|
||||
'Passing null to %s() is deprecated, pass 0 instead.',
|
||||
__METHOD__,
|
||||
);
|
||||
}
|
||||
|
||||
$this->firstResult = $firstResult;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets maxResults.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getMaxResults()
|
||||
{
|
||||
return $this->maxResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets maxResults.
|
||||
*
|
||||
* @param int|null $maxResults The value to set.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMaxResults(int|null $maxResults)
|
||||
{
|
||||
$this->maxResults = $maxResults;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
222
vendor/doctrine/collections/src/Expr/ClosureExpressionVisitor.php
vendored
Normal file
222
vendor/doctrine/collections/src/Expr/ClosureExpressionVisitor.php
vendored
Normal file
@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
use ArrayAccess;
|
||||
use Closure;
|
||||
use RuntimeException;
|
||||
|
||||
use function explode;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_scalar;
|
||||
use function iterator_to_array;
|
||||
use function method_exists;
|
||||
use function preg_match;
|
||||
use function preg_replace_callback;
|
||||
use function str_contains;
|
||||
use function str_ends_with;
|
||||
use function str_starts_with;
|
||||
use function strtoupper;
|
||||
|
||||
/**
|
||||
* Walks an expression graph and turns it into a PHP closure.
|
||||
*
|
||||
* This closure can be used with {@Collection#filter()} and is used internally
|
||||
* by {@ArrayCollection#select()}.
|
||||
*/
|
||||
class ClosureExpressionVisitor extends ExpressionVisitor
|
||||
{
|
||||
/**
|
||||
* Accesses the field of a given object. This field has to be public
|
||||
* directly or indirectly (through an accessor get*, is*, or a magic
|
||||
* method, __get, __call).
|
||||
*
|
||||
* @param object|mixed[] $object
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getObjectFieldValue(object|array $object, string $field)
|
||||
{
|
||||
if (str_contains($field, '.')) {
|
||||
[$field, $subField] = explode('.', $field, 2);
|
||||
$object = self::getObjectFieldValue($object, $field);
|
||||
|
||||
return self::getObjectFieldValue($object, $subField);
|
||||
}
|
||||
|
||||
if (is_array($object)) {
|
||||
return $object[$field];
|
||||
}
|
||||
|
||||
$accessors = ['get', 'is', ''];
|
||||
|
||||
foreach ($accessors as $accessor) {
|
||||
$accessor .= $field;
|
||||
|
||||
if (method_exists($object, $accessor)) {
|
||||
return $object->$accessor();
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match('/^is[A-Z]+/', $field) === 1 && method_exists($object, $field)) {
|
||||
return $object->$field();
|
||||
}
|
||||
|
||||
// __call should be triggered for get.
|
||||
$accessor = $accessors[0] . $field;
|
||||
|
||||
if (method_exists($object, '__call')) {
|
||||
return $object->$accessor();
|
||||
}
|
||||
|
||||
if ($object instanceof ArrayAccess) {
|
||||
return $object[$field];
|
||||
}
|
||||
|
||||
if (isset($object->$field)) {
|
||||
return $object->$field;
|
||||
}
|
||||
|
||||
// camelcase field name to support different variable naming conventions
|
||||
$ccField = preg_replace_callback('/_(.?)/', static fn ($matches) => strtoupper((string) $matches[1]), $field);
|
||||
|
||||
foreach ($accessors as $accessor) {
|
||||
$accessor .= $ccField;
|
||||
|
||||
if (method_exists($object, $accessor)) {
|
||||
return $object->$accessor();
|
||||
}
|
||||
}
|
||||
|
||||
return $object->$field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for sorting arrays of objects based on multiple fields + orientations.
|
||||
*
|
||||
* @return Closure
|
||||
*/
|
||||
public static function sortByField(string $name, int $orientation = 1, Closure|null $next = null)
|
||||
{
|
||||
if (! $next) {
|
||||
$next = static fn (): int => 0;
|
||||
}
|
||||
|
||||
return static function ($a, $b) use ($name, $next, $orientation): int {
|
||||
$aValue = ClosureExpressionVisitor::getObjectFieldValue($a, $name);
|
||||
|
||||
$bValue = ClosureExpressionVisitor::getObjectFieldValue($b, $name);
|
||||
|
||||
if ($aValue === $bValue) {
|
||||
return $next($a, $b);
|
||||
}
|
||||
|
||||
return ($aValue > $bValue ? 1 : -1) * $orientation;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function walkComparison(Comparison $comparison)
|
||||
{
|
||||
$field = $comparison->getField();
|
||||
$value = $comparison->getValue()->getValue();
|
||||
|
||||
return match ($comparison->getOperator()) {
|
||||
Comparison::EQ => static fn ($object): bool => self::getObjectFieldValue($object, $field) === $value,
|
||||
Comparison::NEQ => static fn ($object): bool => self::getObjectFieldValue($object, $field) !== $value,
|
||||
Comparison::LT => static fn ($object): bool => self::getObjectFieldValue($object, $field) < $value,
|
||||
Comparison::LTE => static fn ($object): bool => self::getObjectFieldValue($object, $field) <= $value,
|
||||
Comparison::GT => static fn ($object): bool => self::getObjectFieldValue($object, $field) > $value,
|
||||
Comparison::GTE => static fn ($object): bool => self::getObjectFieldValue($object, $field) >= $value,
|
||||
Comparison::IN => static function ($object) use ($field, $value): bool {
|
||||
$fieldValue = ClosureExpressionVisitor::getObjectFieldValue($object, $field);
|
||||
|
||||
return in_array($fieldValue, $value, is_scalar($fieldValue));
|
||||
},
|
||||
Comparison::NIN => static function ($object) use ($field, $value): bool {
|
||||
$fieldValue = ClosureExpressionVisitor::getObjectFieldValue($object, $field);
|
||||
|
||||
return ! in_array($fieldValue, $value, is_scalar($fieldValue));
|
||||
},
|
||||
Comparison::CONTAINS => static fn ($object): bool => str_contains((string) self::getObjectFieldValue($object, $field), (string) $value),
|
||||
Comparison::MEMBER_OF => static function ($object) use ($field, $value): bool {
|
||||
$fieldValues = ClosureExpressionVisitor::getObjectFieldValue($object, $field);
|
||||
|
||||
if (! is_array($fieldValues)) {
|
||||
$fieldValues = iterator_to_array($fieldValues);
|
||||
}
|
||||
|
||||
return in_array($value, $fieldValues, true);
|
||||
},
|
||||
Comparison::STARTS_WITH => static fn ($object): bool => str_starts_with((string) self::getObjectFieldValue($object, $field), (string) $value),
|
||||
Comparison::ENDS_WITH => static fn ($object): bool => str_ends_with((string) self::getObjectFieldValue($object, $field), (string) $value),
|
||||
default => throw new RuntimeException('Unknown comparison operator: ' . $comparison->getOperator()),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function walkValue(Value $value)
|
||||
{
|
||||
return $value->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function walkCompositeExpression(CompositeExpression $expr)
|
||||
{
|
||||
$expressionList = [];
|
||||
|
||||
foreach ($expr->getExpressionList() as $child) {
|
||||
$expressionList[] = $this->dispatch($child);
|
||||
}
|
||||
|
||||
return match ($expr->getType()) {
|
||||
CompositeExpression::TYPE_AND => $this->andExpressions($expressionList),
|
||||
CompositeExpression::TYPE_OR => $this->orExpressions($expressionList),
|
||||
CompositeExpression::TYPE_NOT => $this->notExpression($expressionList),
|
||||
default => throw new RuntimeException('Unknown composite ' . $expr->getType()),
|
||||
};
|
||||
}
|
||||
|
||||
/** @param callable[] $expressions */
|
||||
private function andExpressions(array $expressions): Closure
|
||||
{
|
||||
return static function ($object) use ($expressions): bool {
|
||||
foreach ($expressions as $expression) {
|
||||
if (! $expression($object)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
/** @param callable[] $expressions */
|
||||
private function orExpressions(array $expressions): Closure
|
||||
{
|
||||
return static function ($object) use ($expressions): bool {
|
||||
foreach ($expressions as $expression) {
|
||||
if ($expression($object)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
/** @param callable[] $expressions */
|
||||
private function notExpression(array $expressions): Closure
|
||||
{
|
||||
return static fn ($object) => ! $expressions[0]($object);
|
||||
}
|
||||
}
|
62
vendor/doctrine/collections/src/Expr/Comparison.php
vendored
Normal file
62
vendor/doctrine/collections/src/Expr/Comparison.php
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
/**
|
||||
* Comparison of a field with a value by the given operator.
|
||||
*/
|
||||
class Comparison implements Expression
|
||||
{
|
||||
final public const EQ = '=';
|
||||
final public const NEQ = '<>';
|
||||
final public const LT = '<';
|
||||
final public const LTE = '<=';
|
||||
final public const GT = '>';
|
||||
final public const GTE = '>=';
|
||||
final public const IS = '='; // no difference with EQ
|
||||
final public const IN = 'IN';
|
||||
final public const NIN = 'NIN';
|
||||
final public const CONTAINS = 'CONTAINS';
|
||||
final public const MEMBER_OF = 'MEMBER_OF';
|
||||
final public const STARTS_WITH = 'STARTS_WITH';
|
||||
final public const ENDS_WITH = 'ENDS_WITH';
|
||||
|
||||
private readonly Value $value;
|
||||
|
||||
public function __construct(private readonly string $field, private readonly string $op, mixed $value)
|
||||
{
|
||||
if (! ($value instanceof Value)) {
|
||||
$value = new Value($value);
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/** @return string */
|
||||
public function getField()
|
||||
{
|
||||
return $this->field;
|
||||
}
|
||||
|
||||
/** @return Value */
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/** @return string */
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->op;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function visit(ExpressionVisitor $visitor)
|
||||
{
|
||||
return $visitor->walkComparison($this);
|
||||
}
|
||||
}
|
70
vendor/doctrine/collections/src/Expr/CompositeExpression.php
vendored
Normal file
70
vendor/doctrine/collections/src/Expr/CompositeExpression.php
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Expression of Expressions combined by AND or OR operation.
|
||||
*/
|
||||
class CompositeExpression implements Expression
|
||||
{
|
||||
final public const TYPE_AND = 'AND';
|
||||
final public const TYPE_OR = 'OR';
|
||||
final public const TYPE_NOT = 'NOT';
|
||||
|
||||
/** @var list<Expression> */
|
||||
private array $expressions = [];
|
||||
|
||||
/**
|
||||
* @param Expression[] $expressions
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct(private readonly string $type, array $expressions)
|
||||
{
|
||||
foreach ($expressions as $expr) {
|
||||
if ($expr instanceof Value) {
|
||||
throw new RuntimeException('Values are not supported expressions as children of and/or expressions.');
|
||||
}
|
||||
|
||||
if (! ($expr instanceof Expression)) {
|
||||
throw new RuntimeException('No expression given to CompositeExpression.');
|
||||
}
|
||||
|
||||
$this->expressions[] = $expr;
|
||||
}
|
||||
|
||||
if ($type === self::TYPE_NOT && count($this->expressions) !== 1) {
|
||||
throw new RuntimeException('Not expression only allows one expression as child.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of expressions nested in this composite.
|
||||
*
|
||||
* @return list<Expression>
|
||||
*/
|
||||
public function getExpressionList()
|
||||
{
|
||||
return $this->expressions;
|
||||
}
|
||||
|
||||
/** @return string */
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function visit(ExpressionVisitor $visitor)
|
||||
{
|
||||
return $visitor->walkCompositeExpression($this);
|
||||
}
|
||||
}
|
14
vendor/doctrine/collections/src/Expr/Expression.php
vendored
Normal file
14
vendor/doctrine/collections/src/Expr/Expression.php
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
/**
|
||||
* Expression for the {@link Selectable} interface.
|
||||
*/
|
||||
interface Expression
|
||||
{
|
||||
/** @return mixed */
|
||||
public function visit(ExpressionVisitor $visitor);
|
||||
}
|
52
vendor/doctrine/collections/src/Expr/ExpressionVisitor.php
vendored
Normal file
52
vendor/doctrine/collections/src/Expr/ExpressionVisitor.php
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* An Expression visitor walks a graph of expressions and turns them into a
|
||||
* query for the underlying implementation.
|
||||
*/
|
||||
abstract class ExpressionVisitor
|
||||
{
|
||||
/**
|
||||
* Converts a comparison expression into the target query language output.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function walkComparison(Comparison $comparison);
|
||||
|
||||
/**
|
||||
* Converts a value expression into the target query language part.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function walkValue(Value $value);
|
||||
|
||||
/**
|
||||
* Converts a composite expression into the target query language output.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function walkCompositeExpression(CompositeExpression $expr);
|
||||
|
||||
/**
|
||||
* Dispatches walking an expression to the appropriate handler.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function dispatch(Expression $expr)
|
||||
{
|
||||
return match (true) {
|
||||
$expr instanceof Comparison => $this->walkComparison($expr),
|
||||
$expr instanceof Value => $this->walkValue($expr),
|
||||
$expr instanceof CompositeExpression => $this->walkCompositeExpression($expr),
|
||||
default => throw new RuntimeException('Unknown Expression ' . $expr::class),
|
||||
};
|
||||
}
|
||||
}
|
26
vendor/doctrine/collections/src/Expr/Value.php
vendored
Normal file
26
vendor/doctrine/collections/src/Expr/Value.php
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
class Value implements Expression
|
||||
{
|
||||
public function __construct(private readonly mixed $value)
|
||||
{
|
||||
}
|
||||
|
||||
/** @return mixed */
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function visit(ExpressionVisitor $visitor)
|
||||
{
|
||||
return $visitor->walkValue($this);
|
||||
}
|
||||
}
|
123
vendor/doctrine/collections/src/ExpressionBuilder.php
vendored
Normal file
123
vendor/doctrine/collections/src/ExpressionBuilder.php
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
use Doctrine\Common\Collections\Expr\CompositeExpression;
|
||||
use Doctrine\Common\Collections\Expr\Expression;
|
||||
use Doctrine\Common\Collections\Expr\Value;
|
||||
|
||||
/**
|
||||
* Builder for Expressions in the {@link Selectable} interface.
|
||||
*
|
||||
* Important Notice for interoperable code: You have to use scalar
|
||||
* values only for comparisons, otherwise the behavior of the comparison
|
||||
* may be different between implementations (Array vs ORM vs ODM).
|
||||
*/
|
||||
class ExpressionBuilder
|
||||
{
|
||||
/** @return CompositeExpression */
|
||||
public function andX(Expression ...$expressions)
|
||||
{
|
||||
return new CompositeExpression(CompositeExpression::TYPE_AND, $expressions);
|
||||
}
|
||||
|
||||
/** @return CompositeExpression */
|
||||
public function orX(Expression ...$expressions)
|
||||
{
|
||||
return new CompositeExpression(CompositeExpression::TYPE_OR, $expressions);
|
||||
}
|
||||
|
||||
public function not(Expression $expression): CompositeExpression
|
||||
{
|
||||
return new CompositeExpression(CompositeExpression::TYPE_NOT, [$expression]);
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function eq(string $field, mixed $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::EQ, new Value($value));
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function gt(string $field, mixed $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::GT, new Value($value));
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function lt(string $field, mixed $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::LT, new Value($value));
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function gte(string $field, mixed $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::GTE, new Value($value));
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function lte(string $field, mixed $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::LTE, new Value($value));
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function neq(string $field, mixed $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::NEQ, new Value($value));
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function isNull(string $field)
|
||||
{
|
||||
return new Comparison($field, Comparison::EQ, new Value(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $values
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function in(string $field, array $values)
|
||||
{
|
||||
return new Comparison($field, Comparison::IN, new Value($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $values
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function notIn(string $field, array $values)
|
||||
{
|
||||
return new Comparison($field, Comparison::NIN, new Value($values));
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function contains(string $field, mixed $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::CONTAINS, new Value($value));
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function memberOf(string $field, mixed $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::MEMBER_OF, new Value($value));
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function startsWith(string $field, mixed $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::STARTS_WITH, new Value($value));
|
||||
}
|
||||
|
||||
/** @return Comparison */
|
||||
public function endsWith(string $field, mixed $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::ENDS_WITH, new Value($value));
|
||||
}
|
||||
}
|
242
vendor/doctrine/collections/src/ReadableCollection.php
vendored
Normal file
242
vendor/doctrine/collections/src/ReadableCollection.php
vendored
Normal file
@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use Closure;
|
||||
use Countable;
|
||||
use IteratorAggregate;
|
||||
|
||||
/**
|
||||
* @psalm-template TKey of array-key
|
||||
* @template-covariant T
|
||||
* @template-extends IteratorAggregate<TKey, T>
|
||||
*/
|
||||
interface ReadableCollection extends Countable, IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* Checks whether an element is contained in the collection.
|
||||
* This is an O(n) operation, where n is the size of the collection.
|
||||
*
|
||||
* @param mixed $element The element to search for.
|
||||
* @psalm-param TMaybeContained $element
|
||||
*
|
||||
* @return bool TRUE if the collection contains the element, FALSE otherwise.
|
||||
* @psalm-return (TMaybeContained is T ? bool : false)
|
||||
*
|
||||
* @template TMaybeContained
|
||||
*/
|
||||
public function contains(mixed $element);
|
||||
|
||||
/**
|
||||
* Checks whether the collection is empty (contains no elements).
|
||||
*
|
||||
* @return bool TRUE if the collection is empty, FALSE otherwise.
|
||||
*/
|
||||
public function isEmpty();
|
||||
|
||||
/**
|
||||
* Checks whether the collection contains an element with the specified key/index.
|
||||
*
|
||||
* @param string|int $key The key/index to check for.
|
||||
* @psalm-param TKey $key
|
||||
*
|
||||
* @return bool TRUE if the collection contains an element with the specified key/index,
|
||||
* FALSE otherwise.
|
||||
*/
|
||||
public function containsKey(string|int $key);
|
||||
|
||||
/**
|
||||
* Gets the element at the specified key/index.
|
||||
*
|
||||
* @param string|int $key The key/index of the element to retrieve.
|
||||
* @psalm-param TKey $key
|
||||
*
|
||||
* @return mixed
|
||||
* @psalm-return T|null
|
||||
*/
|
||||
public function get(string|int $key);
|
||||
|
||||
/**
|
||||
* Gets all keys/indices of the collection.
|
||||
*
|
||||
* @return int[]|string[] The keys/indices of the collection, in the order of the corresponding
|
||||
* elements in the collection.
|
||||
* @psalm-return list<TKey>
|
||||
*/
|
||||
public function getKeys();
|
||||
|
||||
/**
|
||||
* Gets all values of the collection.
|
||||
*
|
||||
* @return mixed[] The values of all elements in the collection, in the
|
||||
* order they appear in the collection.
|
||||
* @psalm-return list<T>
|
||||
*/
|
||||
public function getValues();
|
||||
|
||||
/**
|
||||
* Gets a native PHP array representation of the collection.
|
||||
*
|
||||
* @return mixed[]
|
||||
* @psalm-return array<TKey,T>
|
||||
*/
|
||||
public function toArray();
|
||||
|
||||
/**
|
||||
* Sets the internal iterator to the first element in the collection and returns this element.
|
||||
*
|
||||
* @return mixed
|
||||
* @psalm-return T|false
|
||||
*/
|
||||
public function first();
|
||||
|
||||
/**
|
||||
* Sets the internal iterator to the last element in the collection and returns this element.
|
||||
*
|
||||
* @return mixed
|
||||
* @psalm-return T|false
|
||||
*/
|
||||
public function last();
|
||||
|
||||
/**
|
||||
* Gets the key/index of the element at the current iterator position.
|
||||
*
|
||||
* @return int|string|null
|
||||
* @psalm-return TKey|null
|
||||
*/
|
||||
public function key();
|
||||
|
||||
/**
|
||||
* Gets the element of the collection at the current iterator position.
|
||||
*
|
||||
* @return mixed
|
||||
* @psalm-return T|false
|
||||
*/
|
||||
public function current();
|
||||
|
||||
/**
|
||||
* Moves the internal iterator position to the next element and returns this element.
|
||||
*
|
||||
* @return mixed
|
||||
* @psalm-return T|false
|
||||
*/
|
||||
public function next();
|
||||
|
||||
/**
|
||||
* Extracts a slice of $length elements starting at position $offset from the Collection.
|
||||
*
|
||||
* If $length is null it returns all elements from $offset to the end of the Collection.
|
||||
* Keys have to be preserved by this method. Calling this method will only return the
|
||||
* selected slice and NOT change the elements contained in the collection slice is called on.
|
||||
*
|
||||
* @param int $offset The offset to start from.
|
||||
* @param int|null $length The maximum number of elements to return, or null for no limit.
|
||||
*
|
||||
* @return mixed[]
|
||||
* @psalm-return array<TKey,T>
|
||||
*/
|
||||
public function slice(int $offset, int|null $length = null);
|
||||
|
||||
/**
|
||||
* Tests for the existence of an element that satisfies the given predicate.
|
||||
*
|
||||
* @param Closure $p The predicate.
|
||||
* @psalm-param Closure(TKey, T):bool $p
|
||||
*
|
||||
* @return bool TRUE if the predicate is TRUE for at least one element, FALSE otherwise.
|
||||
*/
|
||||
public function exists(Closure $p);
|
||||
|
||||
/**
|
||||
* Returns all the elements of this collection that satisfy the predicate p.
|
||||
* The order of the elements is preserved.
|
||||
*
|
||||
* @param Closure $p The predicate used for filtering.
|
||||
* @psalm-param Closure(T, TKey):bool $p
|
||||
*
|
||||
* @return ReadableCollection<mixed> A collection with the results of the filter operation.
|
||||
* @psalm-return ReadableCollection<TKey, T>
|
||||
*/
|
||||
public function filter(Closure $p);
|
||||
|
||||
/**
|
||||
* Applies the given function to each element in the collection and returns
|
||||
* a new collection with the elements returned by the function.
|
||||
*
|
||||
* @psalm-param Closure(T):U $func
|
||||
*
|
||||
* @return ReadableCollection<mixed>
|
||||
* @psalm-return ReadableCollection<TKey, U>
|
||||
*
|
||||
* @psalm-template U
|
||||
*/
|
||||
public function map(Closure $func);
|
||||
|
||||
/**
|
||||
* Partitions this collection in two collections according to a predicate.
|
||||
* Keys are preserved in the resulting collections.
|
||||
*
|
||||
* @param Closure $p The predicate on which to partition.
|
||||
* @psalm-param Closure(TKey, T):bool $p
|
||||
*
|
||||
* @return ReadableCollection<mixed>[] An array with two elements. The first element contains the collection
|
||||
* of elements where the predicate returned TRUE, the second element
|
||||
* contains the collection of elements where the predicate returned FALSE.
|
||||
* @psalm-return array{0: ReadableCollection<TKey, T>, 1: ReadableCollection<TKey, T>}
|
||||
*/
|
||||
public function partition(Closure $p);
|
||||
|
||||
/**
|
||||
* Tests whether the given predicate p holds for all elements of this collection.
|
||||
*
|
||||
* @param Closure $p The predicate.
|
||||
* @psalm-param Closure(TKey, T):bool $p
|
||||
*
|
||||
* @return bool TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.
|
||||
*/
|
||||
public function forAll(Closure $p);
|
||||
|
||||
/**
|
||||
* Gets the index/key of a given element. The comparison of two elements is strict,
|
||||
* that means not only the value but also the type must match.
|
||||
* For objects this means reference equality.
|
||||
*
|
||||
* @param mixed $element The element to search for.
|
||||
* @psalm-param TMaybeContained $element
|
||||
*
|
||||
* @return int|string|bool The key/index of the element or FALSE if the element was not found.
|
||||
* @psalm-return (TMaybeContained is T ? TKey|false : false)
|
||||
*
|
||||
* @template TMaybeContained
|
||||
*/
|
||||
public function indexOf(mixed $element);
|
||||
|
||||
/**
|
||||
* Returns the first element of this collection that satisfies the predicate p.
|
||||
*
|
||||
* @param Closure $p The predicate.
|
||||
* @psalm-param Closure(TKey, T):bool $p
|
||||
*
|
||||
* @return mixed The first element respecting the predicate,
|
||||
* null if no element respects the predicate.
|
||||
* @psalm-return T|null
|
||||
*/
|
||||
public function findFirst(Closure $p);
|
||||
|
||||
/**
|
||||
* Applies iteratively the given function to each element in the collection,
|
||||
* so as to reduce the collection to a single value.
|
||||
*
|
||||
* @psalm-param Closure(TReturn|TInitial|null, T):(TInitial|TReturn) $func
|
||||
* @psalm-param TInitial|null $initial
|
||||
*
|
||||
* @return mixed
|
||||
* @psalm-return TReturn|TInitial|null
|
||||
*
|
||||
* @psalm-template TReturn
|
||||
* @psalm-template TInitial
|
||||
*/
|
||||
public function reduce(Closure $func, mixed $initial = null);
|
||||
}
|
32
vendor/doctrine/collections/src/Selectable.php
vendored
Normal file
32
vendor/doctrine/collections/src/Selectable.php
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
/**
|
||||
* Interface for collections that allow efficient filtering with an expression API.
|
||||
*
|
||||
* Goal of this interface is a backend independent method to fetch elements
|
||||
* from a collections. {@link Expression} is crafted in a way that you can
|
||||
* implement queries from both in-memory and database-backed collections.
|
||||
*
|
||||
* For database backed collections this allows very efficient access by
|
||||
* utilizing the query APIs, for example SQL in the ORM. Applications using
|
||||
* this API can implement efficient database access without having to ask the
|
||||
* EntityManager or Repositories.
|
||||
*
|
||||
* @psalm-template TKey as array-key
|
||||
* @psalm-template-covariant T
|
||||
*/
|
||||
interface Selectable
|
||||
{
|
||||
/**
|
||||
* Selects all elements from a selectable that match the expression and
|
||||
* returns a new collection containing these elements and preserved keys.
|
||||
*
|
||||
* @return ReadableCollection<mixed>&Selectable<mixed>
|
||||
* @psalm-return ReadableCollection<TKey,T>&Selectable<TKey,T>
|
||||
*/
|
||||
public function matching(Criteria $criteria);
|
||||
}
|
60
vendor/doctrine/common/.doctrine-project.json
vendored
Normal file
60
vendor/doctrine/common/.doctrine-project.json
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
{
|
||||
"active": true,
|
||||
"name": "Common",
|
||||
"slug": "common",
|
||||
"docsSlug": "doctrine-common",
|
||||
"versions": [
|
||||
{
|
||||
"name": "3.4",
|
||||
"branchName": "3.4.x",
|
||||
"slug": "3.4",
|
||||
"current": true,
|
||||
"aliases": [
|
||||
"current",
|
||||
"stable"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "3.3",
|
||||
"branchName": "3.3.x",
|
||||
"slug": "3.3",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "3.2",
|
||||
"branchName": "3.2.x",
|
||||
"slug": "3.2",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "3.1",
|
||||
"branchName": "3.1.x",
|
||||
"slug": "3.1",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "3.0",
|
||||
"branchName": "3.0.x",
|
||||
"slug": "3.0",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.13",
|
||||
"branchName": "2.13.x",
|
||||
"slug": "2.13",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.12",
|
||||
"branchName": "2.12.x",
|
||||
"slug": "2.12",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "2.11",
|
||||
"branchName": "2.11",
|
||||
"slug": "2.11",
|
||||
"maintained": false
|
||||
}
|
||||
]
|
||||
}
|
19
vendor/doctrine/common/LICENSE
vendored
Normal file
19
vendor/doctrine/common/LICENSE
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2006-2015 Doctrine Project
|
||||
|
||||
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.
|
12
vendor/doctrine/common/README.md
vendored
Normal file
12
vendor/doctrine/common/README.md
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
# Doctrine Common
|
||||
|
||||
[](https://github.com/doctrine/common/actions)
|
||||
[](https://codecov.io/gh/doctrine/common)
|
||||
|
||||
The Doctrine Common project is a library that provides extensions to core PHP functionality.
|
||||
|
||||
## More resources:
|
||||
|
||||
* [Website](https://www.doctrine-project.org/)
|
||||
* [Documentation](https://www.doctrine-project.org/projects/doctrine-common/en/current/)
|
||||
* [Downloads](https://github.com/doctrine/common/releases)
|
39
vendor/doctrine/common/UPGRADE_TO_2_1
vendored
Normal file
39
vendor/doctrine/common/UPGRADE_TO_2_1
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
This document details all the possible changes that you should investigate when updating
|
||||
your project from Doctrine Common 2.0.x to 2.1
|
||||
|
||||
## AnnotationReader changes
|
||||
|
||||
The annotation reader was heavily refactored between 2.0 and 2.1-RC1. In theory the operation of the new reader should be backwards compatible, but it has to be setup differently to work that way:
|
||||
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
// new code necessary starting here
|
||||
$reader->setIgnoreNotImportedAnnotations(true);
|
||||
$reader->setEnableParsePhpImports(false);
|
||||
$reader = new \Doctrine\Common\Annotations\CachedReader(
|
||||
new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()
|
||||
);
|
||||
|
||||
## Annotation Base class or @Annotation
|
||||
|
||||
Beginning after 2.1-RC2 you have to either extend ``Doctrine\Common\Annotations\Annotation`` or add @Annotation to your annotations class-level docblock, otherwise the class will simply be ignored.
|
||||
|
||||
## Removed methods on AnnotationReader
|
||||
|
||||
* AnnotationReader::setAutoloadAnnotations()
|
||||
* AnnotationReader::getAutoloadAnnotations()
|
||||
* AnnotationReader::isAutoloadAnnotations()
|
||||
|
||||
## AnnotationRegistry
|
||||
|
||||
Autoloading through the PHP autoloader is removed from the 2.1 AnnotationReader. Instead you have to use the global AnnotationRegistry for loading purposes:
|
||||
|
||||
\Doctrine\Common\Annotations\AnnotationRegistry::registerFile($fileWithAnnotations);
|
||||
\Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace($namespace, $dirs = null);
|
||||
\Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespaces($namespaces);
|
||||
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader($callable);
|
||||
|
||||
The $callable for registering a loader accepts a class as first and only parameter and must try to silently autoload it. On success true has to be returned.
|
||||
The registerAutoloadNamespace function registers a PSR-0 compatible silent autoloader for all classes with the given namespace in the given directories.
|
||||
If null is passed as directory the include path will be used.
|
||||
|
61
vendor/doctrine/common/UPGRADE_TO_2_2
vendored
Normal file
61
vendor/doctrine/common/UPGRADE_TO_2_2
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
This document details all the possible changes that you should investigate when
|
||||
updating your project from Doctrine Common 2.1 to 2.2:
|
||||
|
||||
## Annotation Changes
|
||||
|
||||
- AnnotationReader::setIgnoreNotImportedAnnotations has been removed, you need to
|
||||
add ignore annotation names which are supposed to be ignored via
|
||||
AnnotationReader::addGlobalIgnoredName
|
||||
|
||||
- AnnotationReader::setAutoloadAnnotations was deprecated by the AnnotationRegistry
|
||||
in 2.1 and has been removed in 2.2
|
||||
|
||||
- AnnotationReader::setEnableParsePhpImports was added to ease transition to the new
|
||||
annotation mechanism in 2.1 and is removed in 2.2
|
||||
|
||||
- AnnotationReader::isParsePhpImportsEnabled is removed (see above)
|
||||
|
||||
- AnnotationReader::setDefaultAnnotationNamespace was deprecated in favor of explicit
|
||||
configuration in 2.1 and will be removed in 2.2 (for isolated projects where you
|
||||
have full-control over _all_ available annotations, we offer a dedicated reader
|
||||
class ``SimpleAnnotationReader``)
|
||||
|
||||
- AnnotationReader::setAnnotationCreationFunction was deprecated in 2.1 and will be
|
||||
removed in 2.2. We only offer two creation mechanisms which cannot be changed
|
||||
anymore to allow the same reader instance to work with all annotations regardless
|
||||
of which library they are coming from.
|
||||
|
||||
- AnnotationReader::setAnnotationNamespaceAlias was deprecated in 2.1 and will be
|
||||
removed in 2.2 (see setDefaultAnnotationNamespace)
|
||||
|
||||
- If you use a class as annotation which has not the @Annotation marker in it's
|
||||
class block, we will now throw an exception instead of silently ignoring it. You
|
||||
can however still achieve the previous behavior using the @IgnoreAnnotation, or
|
||||
AnnotationReader::addGlobalIgnoredName (the exception message will contain detailed
|
||||
instructions when you run into this problem).
|
||||
|
||||
## Cache Changes
|
||||
|
||||
- Renamed old AbstractCache to CacheProvider
|
||||
|
||||
- Dropped the support to the following functions of all cache providers:
|
||||
|
||||
- CacheProvider::deleteByWildcard
|
||||
|
||||
- CacheProvider::deleteByRegEx
|
||||
|
||||
- CacheProvider::deleteByPrefix
|
||||
|
||||
- CacheProvider::deleteBySuffix
|
||||
|
||||
- CacheProvider::deleteAll will not remove ALL entries, it will only mark them as invalid
|
||||
|
||||
- CacheProvider::flushAll will remove ALL entries, namespaced or not
|
||||
|
||||
- Added support to MemcachedCache
|
||||
|
||||
- Added support to WincacheCache
|
||||
|
||||
## ClassLoader Changes
|
||||
|
||||
- ClassLoader::fileExistsInIncludePath() no longer exists. Use the native stream_resolve_include_path() PHP function
|
50
vendor/doctrine/common/composer.json
vendored
Normal file
50
vendor/doctrine/common/composer.json
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "doctrine/common",
|
||||
"type": "library",
|
||||
"description": "PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, proxies and much more.",
|
||||
"keywords": [
|
||||
"php",
|
||||
"common",
|
||||
"doctrine"
|
||||
],
|
||||
"homepage": "https://www.doctrine-project.org/projects/common.html",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"},
|
||||
{"name": "Roman Borschel", "email": "roman@code-factory.org"},
|
||||
{"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"},
|
||||
{"name": "Jonathan Wage", "email": "jonwage@gmail.com"},
|
||||
{"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"},
|
||||
{"name": "Marco Pivetta", "email": "ocramius@gmail.com"}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1 || ^8.0",
|
||||
"doctrine/persistence": "^2.0 || ^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/collections": "^1",
|
||||
"phpstan/phpstan": "^1.4.1",
|
||||
"phpstan/phpstan-phpunit": "^1",
|
||||
"phpunit/phpunit": "^7.5.20 || ^8.5 || ^9.0",
|
||||
"doctrine/coding-standard": "^9.0 || ^10.0",
|
||||
"squizlabs/php_codesniffer": "^3.0",
|
||||
"symfony/phpunit-bridge": "^6.1",
|
||||
"vimeo/psalm": "^4.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Common\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Tests\\": "tests"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true,
|
||||
"composer/package-versions-deprecated": true
|
||||
}
|
||||
}
|
||||
}
|
10
vendor/doctrine/common/docs/en/index.rst
vendored
Normal file
10
vendor/doctrine/common/docs/en/index.rst
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
Common Documentation
|
||||
====================
|
||||
|
||||
Welcome to the Doctrine Common Library documentation.
|
||||
|
||||
.. toctree::
|
||||
:depth: 2
|
||||
:glob:
|
||||
|
||||
*
|
241
vendor/doctrine/common/docs/en/reference/class-loading.rst
vendored
Normal file
241
vendor/doctrine/common/docs/en/reference/class-loading.rst
vendored
Normal file
@ -0,0 +1,241 @@
|
||||
Class Loading
|
||||
=============
|
||||
|
||||
Class loading is an essential part of any PHP application that
|
||||
makes heavy use of classes and interfaces. Unfortunately, a lot of
|
||||
people and projects spend a lot of time and effort on custom and
|
||||
specialized class loading strategies. It can quickly become a pain
|
||||
to understand what is going on when using multiple libraries and/or
|
||||
frameworks, each with its own way to do class loading. Class
|
||||
loading should be simple and it is an ideal candidate for
|
||||
convention over configuration.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
The Doctrine Common ClassLoader implements a simple and efficient
|
||||
approach to class loading that is easy to understand and use. The
|
||||
implementation is based on the widely used and accepted convention
|
||||
of mapping namespace and class names to a directory structure. This
|
||||
approach is used for example by Symfony2, the Zend Framework and of
|
||||
course, Doctrine.
|
||||
|
||||
For example, the following class:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
namespace MyProject\Shipping;
|
||||
class ShippingStrategy { ... }
|
||||
|
||||
resides in the following directory structure:
|
||||
|
||||
::
|
||||
|
||||
src/
|
||||
/MyProject
|
||||
/Shipping
|
||||
ShippingStrategy.php
|
||||
|
||||
Note that the name of "src" or the structure above or beside this
|
||||
directory is completely arbitrary. "src" could be named "classes"
|
||||
or "lib" or whatever. The only convention to adhere to is to map
|
||||
namespaces to directories and classes to files named after the
|
||||
class name.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
To use a Doctrine Common ClassLoader, you first need to load the
|
||||
class file containing the ClassLoader. This is the only class file
|
||||
that actually needs to be loaded explicitly via ``require``. All
|
||||
other classes will be loaded on demand by the configured class
|
||||
loaders.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
use Doctrine\Common\ClassLoader;
|
||||
require '/path/to/Doctrine/Common/ClassLoader.php';
|
||||
$classLoader = new ClassLoader('MyProject', '/path/to/src');
|
||||
|
||||
A ``ClassLoader`` takes two constructor parameters, both optional.
|
||||
In the normal case both arguments are supplied. The first argument
|
||||
specifies the namespace prefix this class loader should be
|
||||
responsible for and the second parameter is the path to the root
|
||||
directory where the classes can be found according to the
|
||||
convention mentioned previously.
|
||||
|
||||
The class loader in the example above would thus be responsible for
|
||||
all classes under the 'MyProject' namespace and it would look for
|
||||
the class files starting at the directory '/path/to/src'.
|
||||
|
||||
Also note that the prefix supplied in the first argument need not
|
||||
be a root namespace but can be an arbitrarily nested namespace as
|
||||
well. This allows you to even have the sources of subnamespaces
|
||||
split across different directories. For example, all projects under
|
||||
the Doctrine umbrella reside in the Doctrine namespace, yet the
|
||||
sources for each project usually do not reside under a common root
|
||||
directory. The following is an example of configuring three class
|
||||
loaders, one for each used Doctrine project:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
use Doctrine\Common\ClassLoader;
|
||||
require '/path/to/Doctrine/Common/ClassLoader.php';
|
||||
$commonLoader = new ClassLoader('Doctrine\Common', '/path/to/common/lib');
|
||||
$dbalLoader = new ClassLoader('Doctrine\DBAL', '/path/to/dbal/lib');
|
||||
$ormLoader = new ClassLoader('Doctrine\ORM', '/path/to/orm/lib');
|
||||
$commonLoader->register();
|
||||
$dbalLoader->register();
|
||||
$ormLoader->register();
|
||||
|
||||
Do not be afraid of using multiple class loaders. Due to the
|
||||
efficient class loading design you will not incur much overhead
|
||||
from using many class loaders. Take a look at the implementation of
|
||||
``ClassLoader#loadClass`` to see how simple and efficient the class
|
||||
loading is. The iteration over the installed class loaders happens
|
||||
in C (with the exception of using ``ClassLoader::classExists``).
|
||||
|
||||
A ClassLoader can be used in the following other variations,
|
||||
however, these are rarely used/needed:
|
||||
|
||||
|
||||
- If only the second argument is not supplied, the class loader
|
||||
will be responsible for the namespace prefix given in the first
|
||||
argument and it will rely on the PHP include_path.
|
||||
|
||||
- If only the first argument is not supplied, the class loader
|
||||
will be responsible for *all* classes and it will try to look up
|
||||
*all* classes starting at the directory given as the second
|
||||
argument.
|
||||
|
||||
- If both arguments are not supplied, the class loader will be
|
||||
responsible for *all* classes and it will rely on the PHP
|
||||
include_path.
|
||||
|
||||
|
||||
File Extension
|
||||
--------------
|
||||
|
||||
By default, a ClassLoader uses the ``.php`` file extension for all
|
||||
class files. You can change this behavior, for example to use a
|
||||
ClassLoader to load classes from a library that uses the
|
||||
".class.php" convention (but it must nevertheless adhere to the
|
||||
directory structure convention!):
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
$customLoader = new ClassLoader('CustomLib', '/path/to/custom/lib');
|
||||
$customLoader->setFileExtension('.class.php');
|
||||
$customLoader->register();
|
||||
|
||||
Namespace Separator
|
||||
-------------------
|
||||
|
||||
By default, a ClassLoader uses the ``\`` namespace separator. You
|
||||
can change this behavior, for example to use a ClassLoader to load
|
||||
legacy Zend Framework classes that still use the underscore "_"
|
||||
separator:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
$zend1Loader = new ClassLoader('Zend', '/path/to/zend/lib');
|
||||
$zend1Loader->setNamespaceSeparator('_');
|
||||
$zend1Loader->register();
|
||||
|
||||
Failing Silently and class_exists
|
||||
----------------------------------
|
||||
|
||||
A lot of class/autoloaders these days try to fail silently when a
|
||||
class file is not found. For the most part this is necessary in
|
||||
order to support using ``class_exists('ClassName', true)`` which is
|
||||
supposed to return a boolean value but triggers autoloading. This
|
||||
is a bad thing as it basically forces class loaders to fail
|
||||
silently, which in turn requires costly file_exists or fopen calls
|
||||
for each class being loaded, even though in at least 99% of the
|
||||
cases this is not necessary (compare the number of
|
||||
class_exists(..., true) invocations to the total number of classes
|
||||
being loaded in a request).
|
||||
|
||||
The Doctrine Common ClassLoader does not fail silently, by design.
|
||||
It therefore does not need any costly checks for file existence. A
|
||||
ClassLoader is always responsible for all classes with a certain
|
||||
namespace prefix and if a class is requested to be loaded and can
|
||||
not be found this is considered to be a fatal error. This also
|
||||
means that using class_exists(..., true) to check for class
|
||||
existence when using a Doctrine Common ClassLoader is not possible
|
||||
but this is not a bad thing. What class\_exists(..., true) actually
|
||||
means is two things: 1) Check whether the class is already
|
||||
defined/exists (i.e. class_exists(..., false)) and if not 2) check
|
||||
whether a class file can be loaded for that class. In the Doctrine
|
||||
Common ClassLoader the two responsibilities of loading a class and
|
||||
checking for its existence are separated, which can be observed by
|
||||
the existence of the two methods ``loadClass`` and
|
||||
``canLoadClass``. Thereby ``loadClass`` does not invoke
|
||||
``canLoadClass`` internally, by design. However, you are free to
|
||||
use it yourself to check whether a class can be loaded and the
|
||||
following code snippet is thus equivalent to class\_exists(...,
|
||||
true):
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
// Equivalent to if (('Foo', true)) if there is only 1 class loader to check
|
||||
if (class_exists('Foo', false) || $classLoader->canLoadClass('Foo')) {
|
||||
// ...
|
||||
}
|
||||
|
||||
The only problem with this is that it is inconvenient as you need
|
||||
to have a reference to the class loaders around (and there are
|
||||
often multiple class loaders in use). Therefore, a simpler
|
||||
alternative exists for the cases in which you really want to ask
|
||||
all installed class loaders whether they can load the class:
|
||||
``ClassLoader::classExists($className)``:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
// Equivalent to if (class_exists('Foo', true))
|
||||
if (ClassLoader::classExists('Foo')) {
|
||||
// ...
|
||||
}
|
||||
|
||||
This static method can basically be used as a drop-in replacement
|
||||
for class_exists(..., true). It iterates over all installed class
|
||||
loaders and asks each of them via ``canLoadClass``, returning early
|
||||
(with TRUE) as soon as one class loader returns TRUE from
|
||||
``canLoadClass``. If this sounds like it can potentially be rather
|
||||
costly then because that is true but it is exactly the same thing
|
||||
that class_exists(..., true) does under the hood, it triggers a
|
||||
complete interaction of all class/auto loaders. Checking for class
|
||||
existence via invoking autoloading was never a cheap thing to do
|
||||
but now it is more obvious and more importantly, this check is no
|
||||
longer interleaved with regular class loading, which avoids having
|
||||
to check each and every class for existence prior to loading it.
|
||||
The vast majority of classes to be loaded are *not* optional and a
|
||||
failure to load such a class is, and should be, a fatal error. The
|
||||
ClassLoader design reflects this.
|
||||
|
||||
If you have code that requires the usage of class\_exists(...,
|
||||
true) or ClassLoader::classExists during normal runtime of the
|
||||
application (i.e. on each request) try to refactor your design to
|
||||
avoid it.
|
||||
|
||||
Summary
|
||||
-------
|
||||
|
||||
No matter which class loader you prefer to use (Doctrine classes do
|
||||
not care about how they are loaded), we kindly encourage you to
|
||||
adhere to the simple convention of mapping namespaces and class
|
||||
names to a directory structure.
|
||||
|
||||
Class loading should be simple, automated and uniform. Time is
|
||||
better invested in actual application development than in designing
|
||||
special directory structures, autoloaders and clever caching
|
||||
strategies for class loading.
|
||||
|
||||
|
58
vendor/doctrine/common/phpstan.neon.dist
vendored
Normal file
58
vendor/doctrine/common/phpstan.neon.dist
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
parameters:
|
||||
phpVersion: 80200
|
||||
level: 3
|
||||
paths:
|
||||
- src
|
||||
- tests
|
||||
excludePaths:
|
||||
- tests/Common/Proxy/InvalidReturnTypeClass.php
|
||||
- tests/Common/Proxy/InvalidTypeHintClass.php
|
||||
- tests/Common/Proxy/LazyLoadableObjectWithTypedProperties.php
|
||||
- tests/Common/Proxy/MagicIssetClassWithInteger.php
|
||||
- tests/Common/Proxy/NullableNonOptionalHintClass.php
|
||||
- tests/Common/Proxy/PHP81NeverType.php
|
||||
- tests/Common/Proxy/PHP81IntersectionTypes.php
|
||||
- tests/Common/Proxy/Php8UnionTypes.php
|
||||
- tests/Common/Proxy/Php8StaticType.php
|
||||
- tests/Common/Proxy/ProxyGeneratorTest.php
|
||||
- tests/Common/Proxy/ProxyLogicTypedPropertiesTest.php
|
||||
- tests/Common/Proxy/SerializedClass.php
|
||||
- tests/Common/Proxy/VariadicTypeHintClass.php
|
||||
- tests/Common/Proxy/Php71NullableDefaultedNonOptionalHintClass.php
|
||||
- tests/Common/Proxy/generated
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Doctrine\\Common\\Proxy\\Proxy::\$publicField#'
|
||||
-
|
||||
message: '#^Result of method Doctrine\\Tests\\Common\\Proxy\\LazyLoadableObjectWithVoid::(adding|incrementing)AndReturningVoid\(\) \(void\) is used\.$#'
|
||||
path: 'tests/Common/Proxy/ProxyLogicVoidReturnTypeTest.php'
|
||||
-
|
||||
message: '#^Property Doctrine\\Tests\\Common\\Proxy\\ProxyLogicTest::\$initializerCallbackMock \(callable\(\): mixed&PHPUnit\\Framework\\MockObject\\MockObject\) does not accept PHPUnit\\Framework\\MockObject\\MockObject&stdClass\.$#'
|
||||
path: 'tests/Common/Proxy/ProxyLogicTest.php'
|
||||
-
|
||||
message: '#.*LazyLoadableObject.*#'
|
||||
paths:
|
||||
- 'tests/Common/Proxy/ProxyLogicTest.php'
|
||||
- 'tests/Common/Proxy/ProxyLogicVoidReturnTypeTest.php'
|
||||
-
|
||||
message: '#^Instantiated class Doctrine\\Tests\\Common\\ProxyProxy\\__CG__\\Doctrine\\Tests\\Common\\Proxy\\.* not found.$#'
|
||||
path: 'tests/Common/Proxy/ProxyLogicTest.php'
|
||||
-
|
||||
message: '#^Instantiated class Doctrine\\Tests\\Common\\ProxyProxy\\__CG__\\Doctrine\\Tests\\Common\\Proxy\\.* not found.$#'
|
||||
path: 'tests/Common/Proxy/ProxyLogicVoidReturnTypeTest.php'
|
||||
-
|
||||
message: '#^Property Doctrine\\Tests\\Common\\Proxy\\ProxyLogicVoidReturnTypeTest::\$initializerCallbackMock \(callable\(\): mixed&PHPUnit\\Framework\\MockObject\\MockObject\) does not accept PHPUnit\\Framework\\MockObject\\MockObject&stdClass\.$#'
|
||||
path: 'tests/Common/Proxy/ProxyLogicVoidReturnTypeTest.php'
|
||||
-
|
||||
message: '#^Method Doctrine\\Tests\\Common\\Proxy\\MagicIssetClassWithInteger::__isset\(\) should return bool but returns int\.$#'
|
||||
path: 'tests/Common/Proxy/MagicIssetClassWithInteger.php'
|
||||
-
|
||||
message: '#^Access to an undefined property Doctrine\\Tests\\Common\\Proxy\\MagicGetByRefClass\:\:\$nonExisting\.$#'
|
||||
path: 'tests/Common/Proxy/ProxyMagicMethodsTest.php'
|
||||
|
||||
-
|
||||
message: "#^Class Doctrine\\\\Tests\\\\Common\\\\Proxy\\\\MagicIssetClassWithInteger not found\\.$#"
|
||||
count: 1
|
||||
path: tests/Common/Proxy/ProxyMagicMethodsTest.php
|
||||
includes:
|
||||
- vendor/phpstan/phpstan-phpunit/extension.neon
|
||||
- vendor/phpstan/phpstan-phpunit/rules.neon
|
16
vendor/doctrine/common/psalm.xml
vendored
Normal file
16
vendor/doctrine/common/psalm.xml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<psalm
|
||||
errorLevel="8"
|
||||
resolveFromConfigFile="true"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="https://getpsalm.org/schema/config"
|
||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
||||
phpVersion="8.1"
|
||||
>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
<ignoreFiles>
|
||||
<file name="src/Proxy/ProxyGenerator.php" />
|
||||
</ignoreFiles>
|
||||
</projectFiles>
|
||||
</psalm>
|
285
vendor/doctrine/common/src/ClassLoader.php
vendored
Normal file
285
vendor/doctrine/common/src/ClassLoader.php
vendored
Normal file
@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
use function class_exists;
|
||||
use function interface_exists;
|
||||
use function is_array;
|
||||
use function is_file;
|
||||
use function reset;
|
||||
use function spl_autoload_functions;
|
||||
use function spl_autoload_register;
|
||||
use function spl_autoload_unregister;
|
||||
use function str_replace;
|
||||
use function stream_resolve_include_path;
|
||||
use function strpos;
|
||||
use function trait_exists;
|
||||
use function trigger_error;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use const E_USER_DEPRECATED;
|
||||
|
||||
@trigger_error(ClassLoader::class . ' is deprecated.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* A <tt>ClassLoader</tt> is an autoloader for class files that can be
|
||||
* installed on the SPL autoload stack. It is a class loader that either loads only classes
|
||||
* of a specific namespace or all namespaces and it is suitable for working together
|
||||
* with other autoloaders in the SPL autoload stack.
|
||||
*
|
||||
* If no include path is configured through the constructor or {@link setIncludePath}, a ClassLoader
|
||||
* relies on the PHP <code>include_path</code>.
|
||||
*
|
||||
* @deprecated The ClassLoader is deprecated and will be removed in version 4.0 of doctrine/common.
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
/**
|
||||
* PHP file extension.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fileExtension = '.php';
|
||||
|
||||
/**
|
||||
* Current namespace.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $namespace;
|
||||
|
||||
/**
|
||||
* Current include path.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $includePath;
|
||||
|
||||
/**
|
||||
* PHP namespace separator.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespaceSeparator = '\\';
|
||||
|
||||
/**
|
||||
* Creates a new <tt>ClassLoader</tt> that loads classes of the
|
||||
* specified namespace from the specified include path.
|
||||
*
|
||||
* If no include path is given, the ClassLoader relies on the PHP include_path.
|
||||
* If neither a namespace nor an include path is given, the ClassLoader will
|
||||
* be responsible for loading all classes, thereby relying on the PHP include_path.
|
||||
*
|
||||
* @param string|null $ns The namespace of the classes to load.
|
||||
* @param string|null $includePath The base include path to use.
|
||||
*/
|
||||
public function __construct($ns = null, $includePath = null)
|
||||
{
|
||||
$this->namespace = $ns;
|
||||
$this->includePath = $includePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the namespace separator used by classes in the namespace of this ClassLoader.
|
||||
*
|
||||
* @param string $sep The separator to use.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setNamespaceSeparator($sep)
|
||||
{
|
||||
$this->namespaceSeparator = $sep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace separator used by classes in the namespace of this ClassLoader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespaceSeparator()
|
||||
{
|
||||
return $this->namespaceSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base include path for all class files in the namespace of this ClassLoader.
|
||||
*
|
||||
* @param string|null $includePath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setIncludePath($includePath)
|
||||
{
|
||||
$this->includePath = $includePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the base include path for all class files in the namespace of this ClassLoader.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getIncludePath()
|
||||
{
|
||||
return $this->includePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file extension of class files in the namespace of this ClassLoader.
|
||||
*
|
||||
* @param string $fileExtension
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFileExtension($fileExtension)
|
||||
{
|
||||
$this->fileExtension = $fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file extension of class files in the namespace of this ClassLoader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileExtension()
|
||||
{
|
||||
return $this->fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this ClassLoader on the SPL autoload stack.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
spl_autoload_register([$this, 'loadClass']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this ClassLoader from the SPL autoload stack.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister([$this, 'loadClass']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $className The name of the class to load.
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return bool TRUE if the class has been successfully loaded, FALSE otherwise.
|
||||
*/
|
||||
public function loadClass($className)
|
||||
{
|
||||
if (self::typeExists($className)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $this->canLoadClass($className)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
require($this->includePath !== null ? $this->includePath . DIRECTORY_SEPARATOR : '')
|
||||
. str_replace($this->namespaceSeparator, DIRECTORY_SEPARATOR, $className)
|
||||
. $this->fileExtension;
|
||||
|
||||
return self::typeExists($className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks this ClassLoader whether it can potentially load the class (file) with
|
||||
* the given name.
|
||||
*
|
||||
* @param string $className The fully-qualified name of the class.
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return bool TRUE if this ClassLoader can load the class, FALSE otherwise.
|
||||
*/
|
||||
public function canLoadClass($className)
|
||||
{
|
||||
if ($this->namespace !== null && strpos($className, $this->namespace . $this->namespaceSeparator) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = str_replace($this->namespaceSeparator, DIRECTORY_SEPARATOR, $className) . $this->fileExtension;
|
||||
|
||||
if ($this->includePath !== null) {
|
||||
return is_file($this->includePath . DIRECTORY_SEPARATOR . $file);
|
||||
}
|
||||
|
||||
return stream_resolve_include_path($file) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a class with a given name exists. A class "exists" if it is either
|
||||
* already defined in the current request or if there is an autoloader on the SPL
|
||||
* autoload stack that is a) responsible for the class in question and b) is able to
|
||||
* load a class file in which the class definition resides.
|
||||
*
|
||||
* If the class is not already defined, each autoloader in the SPL autoload stack
|
||||
* is asked whether it is able to tell if the class exists. If the autoloader is
|
||||
* a <tt>ClassLoader</tt>, {@link canLoadClass} is used, otherwise the autoload
|
||||
* function of the autoloader is invoked and expected to return a value that
|
||||
* evaluates to TRUE if the class (file) exists. As soon as one autoloader reports
|
||||
* that the class exists, TRUE is returned.
|
||||
*
|
||||
* Note that, depending on what kinds of autoloaders are installed on the SPL
|
||||
* autoload stack, the class (file) might already be loaded as a result of checking
|
||||
* for its existence. This is not the case with a <tt>ClassLoader</tt>, who separates
|
||||
* these responsibilities.
|
||||
*
|
||||
* @param string $className The fully-qualified name of the class.
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return bool TRUE if the class exists as per the definition given above, FALSE otherwise.
|
||||
*/
|
||||
public static function classExists($className)
|
||||
{
|
||||
return self::typeExists($className, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the <tt>ClassLoader</tt> from the SPL autoload stack that is responsible
|
||||
* for (and is able to load) the class with the given name.
|
||||
*
|
||||
* @param string $className The name of the class.
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return ClassLoader|null The <tt>ClassLoader</tt> for the class or NULL if no such <tt>ClassLoader</tt> exists.
|
||||
*/
|
||||
public static function getClassLoader($className)
|
||||
{
|
||||
foreach (spl_autoload_functions() as $loader) {
|
||||
if (! is_array($loader)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classLoader = reset($loader);
|
||||
|
||||
if ($classLoader instanceof ClassLoader && $classLoader->canLoadClass($className)) {
|
||||
return $classLoader;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given type exists
|
||||
*
|
||||
* @param string $type
|
||||
* @param bool $autoload
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function typeExists($type, $autoload = false)
|
||||
{
|
||||
return class_exists($type, $autoload)
|
||||
|| interface_exists($type, $autoload)
|
||||
|| trait_exists($type, $autoload);
|
||||
}
|
||||
}
|
14
vendor/doctrine/common/src/CommonException.php
vendored
Normal file
14
vendor/doctrine/common/src/CommonException.php
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Base exception class for package Doctrine\Common.
|
||||
*
|
||||
* @deprecated The doctrine/common package is deprecated, please use specific packages and their exceptions instead.
|
||||
*/
|
||||
class CommonException extends Exception
|
||||
{
|
||||
}
|
26
vendor/doctrine/common/src/Comparable.php
vendored
Normal file
26
vendor/doctrine/common/src/Comparable.php
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
/**
|
||||
* Comparable interface that allows to compare two value objects to each other for similarity.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
interface Comparable
|
||||
{
|
||||
/**
|
||||
* Compares the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantical equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other);
|
||||
}
|
244
vendor/doctrine/common/src/Proxy/AbstractProxyFactory.php
vendored
Normal file
244
vendor/doctrine/common/src/Proxy/AbstractProxyFactory.php
vendored
Normal file
@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Proxy;
|
||||
|
||||
use Doctrine\Common\Proxy\Exception\InvalidArgumentException;
|
||||
use Doctrine\Common\Proxy\Exception\OutOfBoundsException;
|
||||
use Doctrine\Common\Util\ClassUtils;
|
||||
use Doctrine\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
|
||||
|
||||
use function class_exists;
|
||||
use function file_exists;
|
||||
use function filemtime;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* Abstract factory for proxy objects.
|
||||
*/
|
||||
abstract class AbstractProxyFactory
|
||||
{
|
||||
/**
|
||||
* Never autogenerate a proxy and rely that it was generated by some
|
||||
* process before deployment.
|
||||
*/
|
||||
public const AUTOGENERATE_NEVER = 0;
|
||||
|
||||
/**
|
||||
* Always generates a new proxy in every request.
|
||||
*
|
||||
* This is only sane during development.
|
||||
*/
|
||||
public const AUTOGENERATE_ALWAYS = 1;
|
||||
|
||||
/**
|
||||
* Autogenerate the proxy class when the proxy file does not exist.
|
||||
*
|
||||
* This strategy causes a file_exists() call whenever any proxy is used the
|
||||
* first time in a request.
|
||||
*/
|
||||
public const AUTOGENERATE_FILE_NOT_EXISTS = 2;
|
||||
|
||||
/**
|
||||
* Generate the proxy classes using eval().
|
||||
*
|
||||
* This strategy is only sane for development, and even then it gives me
|
||||
* the creeps a little.
|
||||
*/
|
||||
public const AUTOGENERATE_EVAL = 3;
|
||||
|
||||
/**
|
||||
* Autogenerate the proxy class when the proxy file does not exist or
|
||||
* when the proxied file changed.
|
||||
*
|
||||
* This strategy causes a file_exists() call whenever any proxy is used the
|
||||
* first time in a request. When the proxied file is changed, the proxy will
|
||||
* be updated.
|
||||
*/
|
||||
public const AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED = 4;
|
||||
|
||||
private const AUTOGENERATE_MODES = [
|
||||
self::AUTOGENERATE_NEVER,
|
||||
self::AUTOGENERATE_ALWAYS,
|
||||
self::AUTOGENERATE_FILE_NOT_EXISTS,
|
||||
self::AUTOGENERATE_EVAL,
|
||||
self::AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED,
|
||||
];
|
||||
|
||||
/** @var ClassMetadataFactory */
|
||||
private $metadataFactory;
|
||||
|
||||
/** @var ProxyGenerator the proxy generator responsible for creating the proxy classes/files. */
|
||||
private $proxyGenerator;
|
||||
|
||||
/** @var int Whether to automatically (re)generate proxy classes. */
|
||||
private $autoGenerate;
|
||||
|
||||
/** @var ProxyDefinition[] */
|
||||
private $definitions = [];
|
||||
|
||||
/**
|
||||
* @param bool|int $autoGenerate
|
||||
*
|
||||
* @throws InvalidArgumentException When auto generate mode is not valid.
|
||||
*/
|
||||
public function __construct(ProxyGenerator $proxyGenerator, ClassMetadataFactory $metadataFactory, $autoGenerate)
|
||||
{
|
||||
$this->proxyGenerator = $proxyGenerator;
|
||||
$this->metadataFactory = $metadataFactory;
|
||||
$this->autoGenerate = (int) $autoGenerate;
|
||||
|
||||
if (! in_array($this->autoGenerate, self::AUTOGENERATE_MODES, true)) {
|
||||
throw InvalidArgumentException::invalidAutoGenerateMode($autoGenerate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a reference proxy instance for the entity of the given type and identified by
|
||||
* the given identifier.
|
||||
*
|
||||
* @param string $className
|
||||
* @param array<mixed> $identifier
|
||||
*
|
||||
* @return Proxy
|
||||
*
|
||||
* @throws OutOfBoundsException
|
||||
*/
|
||||
public function getProxy($className, array $identifier)
|
||||
{
|
||||
$definition = $this->definitions[$className] ?? $this->getProxyDefinition($className);
|
||||
$fqcn = $definition->proxyClassName;
|
||||
$proxy = new $fqcn($definition->initializer, $definition->cloner);
|
||||
|
||||
foreach ($definition->identifierFields as $idField) {
|
||||
if (! isset($identifier[$idField])) {
|
||||
throw OutOfBoundsException::missingPrimaryKeyValue($className, $idField);
|
||||
}
|
||||
|
||||
$definition->reflectionFields[$idField]->setValue($proxy, $identifier[$idField]);
|
||||
}
|
||||
|
||||
return $proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates proxy classes for all given classes.
|
||||
*
|
||||
* @param ClassMetadata[] $classes The classes (ClassMetadata instances)
|
||||
* for which to generate proxies.
|
||||
* @param string $proxyDir The target directory of the proxy classes. If not specified, the
|
||||
* directory configured on the Configuration of the EntityManager used
|
||||
* by this factory is used.
|
||||
*
|
||||
* @return int Number of generated proxies.
|
||||
*/
|
||||
public function generateProxyClasses(array $classes, $proxyDir = null)
|
||||
{
|
||||
$generated = 0;
|
||||
|
||||
foreach ($classes as $class) {
|
||||
if ($this->skipClass($class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$proxyFileName = $this->proxyGenerator->getProxyFileName($class->getName(), $proxyDir);
|
||||
|
||||
$this->proxyGenerator->generateProxyClass($class, $proxyFileName);
|
||||
|
||||
$generated += 1;
|
||||
}
|
||||
|
||||
return $generated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset initialization/cloning logic for an un-initialized proxy
|
||||
*
|
||||
* @return Proxy
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function resetUninitializedProxy(Proxy $proxy)
|
||||
{
|
||||
if ($proxy->__isInitialized()) {
|
||||
throw InvalidArgumentException::unitializedProxyExpected($proxy);
|
||||
}
|
||||
|
||||
$className = ClassUtils::getClass($proxy);
|
||||
$definition = $this->definitions[$className] ?? $this->getProxyDefinition($className);
|
||||
|
||||
$proxy->__setInitializer($definition->initializer);
|
||||
$proxy->__setCloner($definition->cloner);
|
||||
|
||||
return $proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a proxy definition for the given class name.
|
||||
*
|
||||
* @param string $className
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return ProxyDefinition
|
||||
*/
|
||||
private function getProxyDefinition($className)
|
||||
{
|
||||
$classMetadata = $this->metadataFactory->getMetadataFor($className);
|
||||
$className = $classMetadata->getName(); // aliases and case sensitivity
|
||||
|
||||
$this->definitions[$className] = $this->createProxyDefinition($className);
|
||||
$proxyClassName = $this->definitions[$className]->proxyClassName;
|
||||
|
||||
if (! class_exists($proxyClassName, false)) {
|
||||
$fileName = $this->proxyGenerator->getProxyFileName($className);
|
||||
|
||||
switch ($this->autoGenerate) {
|
||||
case self::AUTOGENERATE_NEVER:
|
||||
require $fileName;
|
||||
break;
|
||||
|
||||
case self::AUTOGENERATE_FILE_NOT_EXISTS:
|
||||
if (! file_exists($fileName)) {
|
||||
$this->proxyGenerator->generateProxyClass($classMetadata, $fileName);
|
||||
}
|
||||
|
||||
require $fileName;
|
||||
break;
|
||||
|
||||
case self::AUTOGENERATE_ALWAYS:
|
||||
$this->proxyGenerator->generateProxyClass($classMetadata, $fileName);
|
||||
require $fileName;
|
||||
break;
|
||||
|
||||
case self::AUTOGENERATE_EVAL:
|
||||
$this->proxyGenerator->generateProxyClass($classMetadata, false);
|
||||
break;
|
||||
|
||||
case self::AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED:
|
||||
if (! file_exists($fileName) || filemtime($fileName) < filemtime($classMetadata->getReflectionClass()->getFileName())) {
|
||||
$this->proxyGenerator->generateProxyClass($classMetadata, $fileName);
|
||||
}
|
||||
|
||||
require $fileName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->definitions[$className];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this class should be skipped during proxy generation.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function skipClass(ClassMetadata $metadata);
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return ProxyDefinition
|
||||
*/
|
||||
abstract protected function createProxyDefinition($className);
|
||||
}
|
99
vendor/doctrine/common/src/Proxy/Autoloader.php
vendored
Normal file
99
vendor/doctrine/common/src/Proxy/Autoloader.php
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Proxy;
|
||||
|
||||
use Closure;
|
||||
use Doctrine\Common\Proxy\Exception\InvalidArgumentException;
|
||||
|
||||
use function call_user_func;
|
||||
use function file_exists;
|
||||
use function is_callable;
|
||||
use function ltrim;
|
||||
use function spl_autoload_register;
|
||||
use function str_replace;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Special Autoloader for Proxy classes, which are not PSR-0 compliant.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class Autoloader
|
||||
{
|
||||
/**
|
||||
* Resolves proxy class name to a filename based on the following pattern.
|
||||
*
|
||||
* 1. Remove Proxy namespace from class name.
|
||||
* 2. Remove namespace separators from remaining class name.
|
||||
* 3. Return PHP filename from proxy-dir with the result from 2.
|
||||
*
|
||||
* @param string $proxyDir
|
||||
* @param string $proxyNamespace
|
||||
* @param string $className
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function resolveFile($proxyDir, $proxyNamespace, $className)
|
||||
{
|
||||
if (strpos($className, $proxyNamespace) !== 0) {
|
||||
throw InvalidArgumentException::notProxyClass($className, $proxyNamespace);
|
||||
}
|
||||
|
||||
// remove proxy namespace from class name
|
||||
$classNameRelativeToProxyNamespace = substr($className, strlen($proxyNamespace));
|
||||
|
||||
// remove namespace separators from remaining class name
|
||||
$fileName = str_replace('\\', '', $classNameRelativeToProxyNamespace);
|
||||
|
||||
return $proxyDir . DIRECTORY_SEPARATOR . $fileName . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers and returns autoloader callback for the given proxy dir and namespace.
|
||||
*
|
||||
* @param string $proxyDir
|
||||
* @param string $proxyNamespace
|
||||
* @param callable|null $notFoundCallback Invoked when the proxy file is not found.
|
||||
*
|
||||
* @return Closure
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function register($proxyDir, $proxyNamespace, $notFoundCallback = null)
|
||||
{
|
||||
$proxyNamespace = ltrim($proxyNamespace, '\\');
|
||||
|
||||
if ($notFoundCallback !== null && ! is_callable($notFoundCallback)) {
|
||||
throw InvalidArgumentException::invalidClassNotFoundCallback($notFoundCallback);
|
||||
}
|
||||
|
||||
$autoloader = static function ($className) use ($proxyDir, $proxyNamespace, $notFoundCallback) {
|
||||
if ($proxyNamespace === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (strpos($className, $proxyNamespace) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file = Autoloader::resolveFile($proxyDir, $proxyNamespace, $className);
|
||||
|
||||
if ($notFoundCallback && ! file_exists($file)) {
|
||||
call_user_func($notFoundCallback, $proxyDir, $proxyNamespace, $className);
|
||||
}
|
||||
|
||||
require $file;
|
||||
};
|
||||
|
||||
spl_autoload_register($autoloader);
|
||||
|
||||
return $autoloader;
|
||||
}
|
||||
}
|
110
vendor/doctrine/common/src/Proxy/Exception/InvalidArgumentException.php
vendored
Normal file
110
vendor/doctrine/common/src/Proxy/Exception/InvalidArgumentException.php
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Proxy\Exception;
|
||||
|
||||
use Doctrine\Persistence\Proxy;
|
||||
use InvalidArgumentException as BaseInvalidArgumentException;
|
||||
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Proxy Invalid Argument Exception.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
class InvalidArgumentException extends BaseInvalidArgumentException implements ProxyException
|
||||
{
|
||||
/** @return self */
|
||||
public static function proxyDirectoryRequired()
|
||||
{
|
||||
return new self('You must configure a proxy directory. See docs for details');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $proxyNamespace
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function notProxyClass($className, $proxyNamespace)
|
||||
{
|
||||
return new self(sprintf('The class "%s" is not part of the proxy namespace "%s"', $className, $proxyNamespace));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function invalidPlaceholder($name)
|
||||
{
|
||||
return new self(sprintf('Provided placeholder for "%s" must be either a string or a valid callable', $name));
|
||||
}
|
||||
|
||||
/** @return self */
|
||||
public static function proxyNamespaceRequired()
|
||||
{
|
||||
return new self('You must configure a proxy namespace');
|
||||
}
|
||||
|
||||
/** @return self */
|
||||
public static function unitializedProxyExpected(Proxy $proxy)
|
||||
{
|
||||
return new self(sprintf('Provided proxy of type "%s" must not be initialized.', get_class($proxy)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $callback
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function invalidClassNotFoundCallback($callback)
|
||||
{
|
||||
$type = is_object($callback) ? get_class($callback) : gettype($callback);
|
||||
|
||||
return new self(sprintf('Invalid \$notFoundCallback given: must be a callable, "%s" given', $type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function classMustNotBeAbstract($className)
|
||||
{
|
||||
return new self(sprintf('Unable to create a proxy for an abstract class "%s".', $className));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function classMustNotBeFinal($className)
|
||||
{
|
||||
return new self(sprintf('Unable to create a proxy for a final class "%s".', $className));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function classMustNotBeReadOnly($className)
|
||||
{
|
||||
return new self(sprintf('Unable to create a proxy for a readonly class "%s".', $className));
|
||||
}
|
||||
|
||||
/** @param mixed $value */
|
||||
public static function invalidAutoGenerateMode($value): self
|
||||
{
|
||||
return new self(sprintf('Invalid auto generate mode "%s" given.', $value));
|
||||
}
|
||||
}
|
27
vendor/doctrine/common/src/Proxy/Exception/OutOfBoundsException.php
vendored
Normal file
27
vendor/doctrine/common/src/Proxy/Exception/OutOfBoundsException.php
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Proxy\Exception;
|
||||
|
||||
use OutOfBoundsException as BaseOutOfBoundsException;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Proxy Invalid Argument Exception.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
class OutOfBoundsException extends BaseOutOfBoundsException implements ProxyException
|
||||
{
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $idField
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function missingPrimaryKeyValue($className, $idField)
|
||||
{
|
||||
return new self(sprintf('Missing value for primary key %s on %s', $idField, $className));
|
||||
}
|
||||
}
|
12
vendor/doctrine/common/src/Proxy/Exception/ProxyException.php
vendored
Normal file
12
vendor/doctrine/common/src/Proxy/Exception/ProxyException.php
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Proxy\Exception;
|
||||
|
||||
/**
|
||||
* Base exception interface for proxy exceptions.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
interface ProxyException
|
||||
{
|
||||
}
|
72
vendor/doctrine/common/src/Proxy/Exception/UnexpectedValueException.php
vendored
Normal file
72
vendor/doctrine/common/src/Proxy/Exception/UnexpectedValueException.php
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Proxy\Exception;
|
||||
|
||||
use Throwable;
|
||||
use UnexpectedValueException as BaseUnexpectedValueException;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Proxy Unexpected Value Exception.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
class UnexpectedValueException extends BaseUnexpectedValueException implements ProxyException
|
||||
{
|
||||
/**
|
||||
* @param string $proxyDirectory
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function proxyDirectoryNotWritable($proxyDirectory)
|
||||
{
|
||||
return new self(sprintf('Your proxy directory "%s" must be writable', $proxyDirectory));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $methodName
|
||||
* @param string $parameterName
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function invalidParameterTypeHint(
|
||||
$className,
|
||||
$methodName,
|
||||
$parameterName,
|
||||
?Throwable $previous = null
|
||||
) {
|
||||
return new self(
|
||||
sprintf(
|
||||
'The type hint of parameter "%s" in method "%s" in class "%s" is invalid.',
|
||||
$parameterName,
|
||||
$methodName,
|
||||
$className
|
||||
),
|
||||
0,
|
||||
$previous
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param string $methodName
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function invalidReturnTypeHint($className, $methodName, ?Throwable $previous = null)
|
||||
{
|
||||
return new self(
|
||||
sprintf(
|
||||
'The return type of method "%s" in class "%s" is invalid.',
|
||||
$methodName,
|
||||
$className
|
||||
),
|
||||
0,
|
||||
$previous
|
||||
);
|
||||
}
|
||||
}
|
68
vendor/doctrine/common/src/Proxy/Proxy.php
vendored
Normal file
68
vendor/doctrine/common/src/Proxy/Proxy.php
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Proxy;
|
||||
|
||||
use Closure;
|
||||
use Doctrine\Persistence\Proxy as BaseProxy;
|
||||
|
||||
/**
|
||||
* Interface for proxy classes.
|
||||
*
|
||||
* @template T of object
|
||||
* @template-extends BaseProxy<T>
|
||||
*/
|
||||
interface Proxy extends BaseProxy
|
||||
{
|
||||
/**
|
||||
* Marks the proxy as initialized or not.
|
||||
*
|
||||
* @param bool $initialized
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __setInitialized($initialized);
|
||||
|
||||
/**
|
||||
* Sets the initializer callback to be used when initializing the proxy. That
|
||||
* initializer should accept 3 parameters: $proxy, $method and $params. Those
|
||||
* are respectively the proxy object that is being initialized, the method name
|
||||
* that triggered initialization and the parameters passed to that method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __setInitializer(?Closure $initializer = null);
|
||||
|
||||
/**
|
||||
* Retrieves the initializer callback used to initialize the proxy.
|
||||
*
|
||||
* @see __setInitializer
|
||||
*
|
||||
* @return Closure|null
|
||||
*/
|
||||
public function __getInitializer();
|
||||
|
||||
/**
|
||||
* Sets the callback to be used when cloning the proxy. That initializer should accept
|
||||
* a single parameter, which is the cloned proxy instance itself.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __setCloner(?Closure $cloner = null);
|
||||
|
||||
/**
|
||||
* Retrieves the callback to be used when cloning the proxy.
|
||||
*
|
||||
* @see __setCloner
|
||||
*
|
||||
* @return Closure|null
|
||||
*/
|
||||
public function __getCloner();
|
||||
|
||||
/**
|
||||
* Retrieves the list of lazy loaded properties for a given proxy
|
||||
*
|
||||
* @return array<string, mixed> Keys are the property names, and values are the default values
|
||||
* for those properties.
|
||||
*/
|
||||
public function __getLazyProperties();
|
||||
}
|
42
vendor/doctrine/common/src/Proxy/ProxyDefinition.php
vendored
Normal file
42
vendor/doctrine/common/src/Proxy/ProxyDefinition.php
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Proxy;
|
||||
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Definition structure how to create a proxy.
|
||||
*/
|
||||
class ProxyDefinition
|
||||
{
|
||||
/** @var string */
|
||||
public $proxyClassName;
|
||||
|
||||
/** @var array<string> */
|
||||
public $identifierFields;
|
||||
|
||||
/** @var ReflectionProperty[] */
|
||||
public $reflectionFields;
|
||||
|
||||
/** @var callable */
|
||||
public $initializer;
|
||||
|
||||
/** @var callable */
|
||||
public $cloner;
|
||||
|
||||
/**
|
||||
* @param string $proxyClassName
|
||||
* @param array<string> $identifierFields
|
||||
* @param array<string, ReflectionProperty> $reflectionFields
|
||||
* @param callable $initializer
|
||||
* @param callable $cloner
|
||||
*/
|
||||
public function __construct($proxyClassName, array $identifierFields, array $reflectionFields, $initializer, $cloner)
|
||||
{
|
||||
$this->proxyClassName = $proxyClassName;
|
||||
$this->identifierFields = $identifierFields;
|
||||
$this->reflectionFields = $reflectionFields;
|
||||
$this->initializer = $initializer;
|
||||
$this->cloner = $cloner;
|
||||
}
|
||||
}
|
1292
vendor/doctrine/common/src/Proxy/ProxyGenerator.php
vendored
Normal file
1292
vendor/doctrine/common/src/Proxy/ProxyGenerator.php
vendored
Normal file
@ -0,0 +1,1292 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Proxy;
|
||||
|
||||
use BackedEnum;
|
||||
use Doctrine\Common\Proxy\Exception\InvalidArgumentException;
|
||||
use Doctrine\Common\Proxy\Exception\UnexpectedValueException;
|
||||
use Doctrine\Common\Util\ClassUtils;
|
||||
use Doctrine\Persistence\Mapping\ClassMetadata;
|
||||
use ReflectionIntersectionType;
|
||||
use ReflectionMethod;
|
||||
use ReflectionNamedType;
|
||||
use ReflectionParameter;
|
||||
use ReflectionProperty;
|
||||
use ReflectionType;
|
||||
use ReflectionUnionType;
|
||||
|
||||
use function array_combine;
|
||||
use function array_diff;
|
||||
use function array_key_exists;
|
||||
use function array_map;
|
||||
use function array_slice;
|
||||
use function array_unique;
|
||||
use function assert;
|
||||
use function bin2hex;
|
||||
use function call_user_func;
|
||||
use function chmod;
|
||||
use function class_exists;
|
||||
use function dirname;
|
||||
use function explode;
|
||||
use function file;
|
||||
use function file_put_contents;
|
||||
use function get_class;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function interface_exists;
|
||||
use function is_callable;
|
||||
use function is_dir;
|
||||
use function is_scalar;
|
||||
use function is_string;
|
||||
use function is_writable;
|
||||
use function lcfirst;
|
||||
use function ltrim;
|
||||
use function method_exists;
|
||||
use function mkdir;
|
||||
use function preg_match;
|
||||
use function preg_match_all;
|
||||
use function preg_replace;
|
||||
use function preg_split;
|
||||
use function random_bytes;
|
||||
use function rename;
|
||||
use function rtrim;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function strpos;
|
||||
use function strrev;
|
||||
use function strtolower;
|
||||
use function strtr;
|
||||
use function substr;
|
||||
use function trim;
|
||||
use function var_export;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use const PHP_VERSION_ID;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
|
||||
/**
|
||||
* This factory is used to generate proxy classes.
|
||||
* It builds proxies from given parameters, a template and class metadata.
|
||||
*/
|
||||
class ProxyGenerator
|
||||
{
|
||||
/**
|
||||
* Used to match very simple id methods that don't need
|
||||
* to be decorated since the identifier is known.
|
||||
*/
|
||||
public const PATTERN_MATCH_ID_METHOD = <<<'EOT'
|
||||
((?(DEFINE)
|
||||
(?<type>\\?[a-z_\x7f-\xff][\w\x7f-\xff]*(?:\\[a-z_\x7f-\xff][\w\x7f-\xff]*)*)
|
||||
(?<intersection_type>(?&type)\s*&\s*(?&type))
|
||||
(?<union_type>(?:(?:\(\s*(?&intersection_type)\s*\))|(?&type))(?:\s*\|\s*(?:(?:\(\s*(?&intersection_type)\s*\))|(?&type)))+)
|
||||
)(?:public\s+)?(?:function\s+%s\s*\(\)\s*)\s*(?::\s*(?:(?&union_type)|(?&intersection_type)|(?:\??(?&type)))\s*)?{\s*return\s*\$this->%s;\s*})i
|
||||
EOT;
|
||||
|
||||
/**
|
||||
* The namespace that contains all proxy classes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $proxyNamespace;
|
||||
|
||||
/**
|
||||
* The directory that contains all proxy classes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $proxyDirectory;
|
||||
|
||||
/**
|
||||
* Map of callables used to fill in placeholders set in the template.
|
||||
*
|
||||
* @var string[]|callable[]
|
||||
*/
|
||||
protected $placeholders = [
|
||||
'baseProxyInterface' => Proxy::class,
|
||||
'additionalProperties' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
* Template used as a blueprint to generate proxies.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $proxyClassTemplate = '<?php
|
||||
|
||||
namespace <namespace>;
|
||||
<enumUseStatements>
|
||||
/**
|
||||
* DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE\'S PROXY GENERATOR
|
||||
*/
|
||||
class <proxyShortClassName> extends \<className> implements \<baseProxyInterface>
|
||||
{
|
||||
/**
|
||||
* @var \Closure the callback responsible for loading properties in the proxy object. This callback is called with
|
||||
* three parameters, being respectively the proxy object to be initialized, the method that triggered the
|
||||
* initialization process and an array of ordered parameters that were passed to that method.
|
||||
*
|
||||
* @see \Doctrine\Common\Proxy\Proxy::__setInitializer
|
||||
*/
|
||||
public $__initializer__;
|
||||
|
||||
/**
|
||||
* @var \Closure the callback responsible of loading properties that need to be copied in the cloned object
|
||||
*
|
||||
* @see \Doctrine\Common\Proxy\Proxy::__setCloner
|
||||
*/
|
||||
public $__cloner__;
|
||||
|
||||
/**
|
||||
* @var boolean flag indicating if this object was already initialized
|
||||
*
|
||||
* @see \Doctrine\Persistence\Proxy::__isInitialized
|
||||
*/
|
||||
public $__isInitialized__ = false;
|
||||
|
||||
/**
|
||||
* @var array<string, null> properties to be lazy loaded, indexed by property name
|
||||
*/
|
||||
public static $lazyPropertiesNames = <lazyPropertiesNames>;
|
||||
|
||||
/**
|
||||
* @var array<string, mixed> default values of properties to be lazy loaded, with keys being the property names
|
||||
*
|
||||
* @see \Doctrine\Common\Proxy\Proxy::__getLazyProperties
|
||||
*/
|
||||
public static $lazyPropertiesDefaults = <lazyPropertiesDefaults>;
|
||||
|
||||
<additionalProperties>
|
||||
|
||||
<constructorImpl>
|
||||
|
||||
<magicGet>
|
||||
|
||||
<magicSet>
|
||||
|
||||
<magicIsset>
|
||||
|
||||
<sleepImpl>
|
||||
|
||||
<wakeupImpl>
|
||||
|
||||
<cloneImpl>
|
||||
|
||||
/**
|
||||
* Forces initialization of the proxy
|
||||
*/
|
||||
public function __load(): void
|
||||
{
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, \'__load\', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @internal generated method: use only when explicitly handling proxy specific loading logic
|
||||
*/
|
||||
public function __isInitialized(): bool
|
||||
{
|
||||
return $this->__isInitialized__;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @internal generated method: use only when explicitly handling proxy specific loading logic
|
||||
*/
|
||||
public function __setInitialized($initialized): void
|
||||
{
|
||||
$this->__isInitialized__ = $initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @internal generated method: use only when explicitly handling proxy specific loading logic
|
||||
*/
|
||||
public function __setInitializer(\Closure $initializer = null): void
|
||||
{
|
||||
$this->__initializer__ = $initializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @internal generated method: use only when explicitly handling proxy specific loading logic
|
||||
*/
|
||||
public function __getInitializer(): ?\Closure
|
||||
{
|
||||
return $this->__initializer__;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @internal generated method: use only when explicitly handling proxy specific loading logic
|
||||
*/
|
||||
public function __setCloner(\Closure $cloner = null): void
|
||||
{
|
||||
$this->__cloner__ = $cloner;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @internal generated method: use only when explicitly handling proxy specific cloning logic
|
||||
*/
|
||||
public function __getCloner(): ?\Closure
|
||||
{
|
||||
return $this->__cloner__;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @internal generated method: use only when explicitly handling proxy specific loading logic
|
||||
* @deprecated no longer in use - generated code now relies on internal components rather than generated public API
|
||||
* @static
|
||||
*/
|
||||
public function __getLazyProperties(): array
|
||||
{
|
||||
return self::$lazyPropertiesDefaults;
|
||||
}
|
||||
|
||||
<methods>
|
||||
}
|
||||
';
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the <tt>ProxyFactory</tt> class that is
|
||||
* connected to the given <tt>EntityManager</tt>.
|
||||
*
|
||||
* @param string $proxyDirectory The directory to use for the proxy classes. It must exist.
|
||||
* @param string $proxyNamespace The namespace to use for the proxy classes.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct($proxyDirectory, $proxyNamespace)
|
||||
{
|
||||
if (! $proxyDirectory) {
|
||||
throw InvalidArgumentException::proxyDirectoryRequired();
|
||||
}
|
||||
|
||||
if (! $proxyNamespace) {
|
||||
throw InvalidArgumentException::proxyNamespaceRequired();
|
||||
}
|
||||
|
||||
$this->proxyDirectory = $proxyDirectory;
|
||||
$this->proxyNamespace = $proxyNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a placeholder to be replaced in the template.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|callable $placeholder
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setPlaceholder($name, $placeholder)
|
||||
{
|
||||
if (! is_string($placeholder) && ! is_callable($placeholder)) {
|
||||
throw InvalidArgumentException::invalidPlaceholder($name);
|
||||
}
|
||||
|
||||
$this->placeholders[$name] = $placeholder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base template used to create proxy classes.
|
||||
*
|
||||
* @param string $proxyClassTemplate
|
||||
*/
|
||||
public function setProxyClassTemplate($proxyClassTemplate)
|
||||
{
|
||||
$this->proxyClassTemplate = (string) $proxyClassTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a proxy class file.
|
||||
*
|
||||
* @param ClassMetadata $class Metadata for the original class.
|
||||
* @param string|bool $fileName Filename (full path) for the generated class. If none is given, eval() is used.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function generateProxyClass(ClassMetadata $class, $fileName = false)
|
||||
{
|
||||
$this->verifyClassCanBeProxied($class);
|
||||
|
||||
preg_match_all('(<([a-zA-Z]+)>)', $this->proxyClassTemplate, $placeholderMatches);
|
||||
|
||||
$placeholderMatches = array_combine($placeholderMatches[0], $placeholderMatches[1]);
|
||||
$placeholders = [];
|
||||
|
||||
foreach ($placeholderMatches as $placeholder => $name) {
|
||||
$placeholders[$placeholder] = $this->placeholders[$name] ?? [$this, 'generate' . $name];
|
||||
}
|
||||
|
||||
foreach ($placeholders as & $placeholder) {
|
||||
if (! is_callable($placeholder)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$placeholder = call_user_func($placeholder, $class);
|
||||
}
|
||||
|
||||
$proxyCode = strtr($this->proxyClassTemplate, $placeholders);
|
||||
|
||||
if (! $fileName) {
|
||||
$proxyClassName = $this->generateNamespace($class) . '\\' . $this->generateProxyShortClassName($class);
|
||||
|
||||
if (! class_exists($proxyClassName)) {
|
||||
eval(substr($proxyCode, 5));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$parentDirectory = dirname($fileName);
|
||||
|
||||
if (! is_dir($parentDirectory) && (@mkdir($parentDirectory, 0775, true) === false)) {
|
||||
throw UnexpectedValueException::proxyDirectoryNotWritable($this->proxyDirectory);
|
||||
}
|
||||
|
||||
if (! is_writable($parentDirectory)) {
|
||||
throw UnexpectedValueException::proxyDirectoryNotWritable($this->proxyDirectory);
|
||||
}
|
||||
|
||||
$tmpFileName = $fileName . '.' . bin2hex(random_bytes(12));
|
||||
|
||||
file_put_contents($tmpFileName, $proxyCode);
|
||||
@chmod($tmpFileName, 0664);
|
||||
rename($tmpFileName, $fileName);
|
||||
}
|
||||
|
||||
/** @throws InvalidArgumentException */
|
||||
private function verifyClassCanBeProxied(ClassMetadata $class)
|
||||
{
|
||||
if ($class->getReflectionClass()->isFinal()) {
|
||||
throw InvalidArgumentException::classMustNotBeFinal($class->getName());
|
||||
}
|
||||
|
||||
if ($class->getReflectionClass()->isAbstract()) {
|
||||
throw InvalidArgumentException::classMustNotBeAbstract($class->getName());
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID >= 80200 && $class->getReflectionClass()->isReadOnly()) {
|
||||
throw InvalidArgumentException::classMustNotBeReadOnly($class->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the proxy short class name to be used in the template.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateProxyShortClassName(ClassMetadata $class)
|
||||
{
|
||||
$proxyClassName = ClassUtils::generateProxyClassName($class->getName(), $this->proxyNamespace);
|
||||
$parts = explode('\\', strrev($proxyClassName), 2);
|
||||
|
||||
return strrev($parts[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the proxy namespace.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateNamespace(ClassMetadata $class)
|
||||
{
|
||||
$proxyClassName = ClassUtils::generateProxyClassName($class->getName(), $this->proxyNamespace);
|
||||
$parts = explode('\\', strrev($proxyClassName), 2);
|
||||
|
||||
return strrev($parts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enums must have a use statement when used as public property defaults.
|
||||
*/
|
||||
public function generateEnumUseStatements(ClassMetadata $class): string
|
||||
{
|
||||
if (PHP_VERSION_ID < 80100) {
|
||||
return "\n";
|
||||
}
|
||||
|
||||
$defaultProperties = $class->getReflectionClass()->getDefaultProperties();
|
||||
$lazyLoadedPublicProperties = $this->getLazyLoadedPublicPropertiesNames($class);
|
||||
$enumClasses = [];
|
||||
|
||||
foreach ($class->getReflectionClass()->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
|
||||
$name = $property->getName();
|
||||
|
||||
if (! in_array($name, $lazyLoadedPublicProperties, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (array_key_exists($name, $defaultProperties) && $defaultProperties[$name] instanceof BackedEnum) {
|
||||
$enumClassNameParts = explode('\\', get_class($defaultProperties[$name]));
|
||||
$enumClasses[] = $enumClassNameParts[0];
|
||||
}
|
||||
}
|
||||
|
||||
return implode(
|
||||
"\n",
|
||||
array_map(
|
||||
static function ($className) {
|
||||
return 'use ' . $className . ';';
|
||||
},
|
||||
array_unique($enumClasses)
|
||||
)
|
||||
) . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the original class name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateClassName(ClassMetadata $class)
|
||||
{
|
||||
return ltrim($class->getName(), '\\');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the array representation of lazy loaded public properties and their default values.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateLazyPropertiesNames(ClassMetadata $class)
|
||||
{
|
||||
$lazyPublicProperties = $this->getLazyLoadedPublicPropertiesNames($class);
|
||||
$values = [];
|
||||
|
||||
foreach ($lazyPublicProperties as $name) {
|
||||
$values[$name] = null;
|
||||
}
|
||||
|
||||
return var_export($values, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the array representation of lazy loaded public properties names.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateLazyPropertiesDefaults(ClassMetadata $class)
|
||||
{
|
||||
return var_export($this->getLazyLoadedPublicProperties($class), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the constructor code (un-setting public lazy loaded properties, setting identifier field values).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateConstructorImpl(ClassMetadata $class)
|
||||
{
|
||||
$constructorImpl = <<<'EOT'
|
||||
public function __construct(?\Closure $initializer = null, ?\Closure $cloner = null)
|
||||
{
|
||||
|
||||
EOT;
|
||||
|
||||
$toUnset = array_map(static function (string $name): string {
|
||||
return '$this->' . $name;
|
||||
}, $this->getLazyLoadedPublicPropertiesNames($class));
|
||||
|
||||
return $constructorImpl . ($toUnset === [] ? '' : ' unset(' . implode(', ', $toUnset) . ");\n")
|
||||
. <<<'EOT'
|
||||
|
||||
$this->__initializer__ = $initializer;
|
||||
$this->__cloner__ = $cloner;
|
||||
}
|
||||
EOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the magic getter invoked when lazy loaded public properties are requested.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateMagicGet(ClassMetadata $class)
|
||||
{
|
||||
$lazyPublicProperties = $this->getLazyLoadedPublicPropertiesNames($class);
|
||||
$reflectionClass = $class->getReflectionClass();
|
||||
$hasParentGet = false;
|
||||
$returnReference = '';
|
||||
$inheritDoc = '';
|
||||
$name = '$name';
|
||||
$parametersString = '$name';
|
||||
$returnTypeHint = null;
|
||||
|
||||
if ($reflectionClass->hasMethod('__get')) {
|
||||
$hasParentGet = true;
|
||||
$inheritDoc = '{@inheritDoc}';
|
||||
$methodReflection = $reflectionClass->getMethod('__get');
|
||||
|
||||
if ($methodReflection->returnsReference()) {
|
||||
$returnReference = '& ';
|
||||
}
|
||||
|
||||
$methodParameters = $methodReflection->getParameters();
|
||||
$name = '$' . $methodParameters[0]->getName();
|
||||
|
||||
$parametersString = $this->buildParametersString($methodReflection->getParameters(), ['name']);
|
||||
$returnTypeHint = $this->getMethodReturnType($methodReflection);
|
||||
}
|
||||
|
||||
if (empty($lazyPublicProperties) && ! $hasParentGet) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$magicGet = <<<EOT
|
||||
/**
|
||||
* $inheritDoc
|
||||
* @param string \$name
|
||||
*/
|
||||
public function {$returnReference}__get($parametersString)$returnTypeHint
|
||||
{
|
||||
|
||||
EOT;
|
||||
|
||||
if (! empty($lazyPublicProperties)) {
|
||||
$magicGet .= <<<'EOT'
|
||||
if (\array_key_exists($name, self::$lazyPropertiesNames)) {
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', [$name]);
|
||||
EOT;
|
||||
|
||||
if ($returnTypeHint === ': void') {
|
||||
$magicGet .= "\n return;";
|
||||
} else {
|
||||
$magicGet .= "\n return \$this->\$name;";
|
||||
}
|
||||
|
||||
$magicGet .= <<<'EOT'
|
||||
|
||||
}
|
||||
|
||||
|
||||
EOT;
|
||||
}
|
||||
|
||||
if ($hasParentGet) {
|
||||
$magicGet .= <<<'EOT'
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__get', [$name]);
|
||||
EOT;
|
||||
|
||||
if ($returnTypeHint === ': void') {
|
||||
$magicGet .= <<<'EOT'
|
||||
|
||||
parent::__get($name);
|
||||
return;
|
||||
EOT;
|
||||
} elseif ($returnTypeHint === ': never') {
|
||||
$magicGet .= <<<'EOT'
|
||||
|
||||
parent::__get($name);
|
||||
EOT;
|
||||
} else {
|
||||
$magicGet .= <<<'EOT'
|
||||
|
||||
return parent::__get($name);
|
||||
EOT;
|
||||
}
|
||||
} else {
|
||||
$magicGet .= sprintf(<<<EOT
|
||||
trigger_error(sprintf('Undefined property: %%s::$%%s', __CLASS__, %s), E_USER_NOTICE);
|
||||
|
||||
EOT
|
||||
, $name);
|
||||
}
|
||||
|
||||
return $magicGet . "\n }";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the magic setter (currently unused).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateMagicSet(ClassMetadata $class)
|
||||
{
|
||||
$lazyPublicProperties = $this->getLazyLoadedPublicPropertiesNames($class);
|
||||
$reflectionClass = $class->getReflectionClass();
|
||||
$hasParentSet = false;
|
||||
$inheritDoc = '';
|
||||
$parametersString = '$name, $value';
|
||||
$returnTypeHint = null;
|
||||
|
||||
if ($reflectionClass->hasMethod('__set')) {
|
||||
$hasParentSet = true;
|
||||
$inheritDoc = '{@inheritDoc}';
|
||||
$methodReflection = $reflectionClass->getMethod('__set');
|
||||
|
||||
$parametersString = $this->buildParametersString($methodReflection->getParameters(), ['name', 'value']);
|
||||
$returnTypeHint = $this->getMethodReturnType($methodReflection);
|
||||
}
|
||||
|
||||
if (empty($lazyPublicProperties) && ! $hasParentSet) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$magicSet = <<<EOT
|
||||
/**
|
||||
* $inheritDoc
|
||||
* @param string \$name
|
||||
* @param mixed \$value
|
||||
*/
|
||||
public function __set($parametersString)$returnTypeHint
|
||||
{
|
||||
|
||||
EOT;
|
||||
|
||||
if (! empty($lazyPublicProperties)) {
|
||||
$magicSet .= <<<'EOT'
|
||||
if (\array_key_exists($name, self::$lazyPropertiesNames)) {
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__set', [$name, $value]);
|
||||
|
||||
$this->$name = $value;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
EOT;
|
||||
}
|
||||
|
||||
if ($hasParentSet) {
|
||||
$magicSet .= <<<'EOT'
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__set', [$name, $value]);
|
||||
EOT;
|
||||
|
||||
if ($returnTypeHint === ': void') {
|
||||
$magicSet .= <<<'EOT'
|
||||
|
||||
parent::__set($name, $value);
|
||||
return;
|
||||
EOT;
|
||||
} elseif ($returnTypeHint === ': never') {
|
||||
$magicSet .= <<<'EOT'
|
||||
|
||||
parent::__set($name, $value);
|
||||
EOT;
|
||||
} else {
|
||||
$magicSet .= <<<'EOT'
|
||||
|
||||
return parent::__set($name, $value);
|
||||
EOT;
|
||||
}
|
||||
} else {
|
||||
$magicSet .= ' $this->$name = $value;';
|
||||
}
|
||||
|
||||
return $magicSet . "\n }";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the magic issetter invoked when lazy loaded public properties are checked against isset().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateMagicIsset(ClassMetadata $class)
|
||||
{
|
||||
$lazyPublicProperties = $this->getLazyLoadedPublicPropertiesNames($class);
|
||||
$hasParentIsset = $class->getReflectionClass()->hasMethod('__isset');
|
||||
$parametersString = '$name';
|
||||
$returnTypeHint = null;
|
||||
|
||||
if ($hasParentIsset) {
|
||||
$methodReflection = $class->getReflectionClass()->getMethod('__isset');
|
||||
$parametersString = $this->buildParametersString($methodReflection->getParameters(), ['name']);
|
||||
$returnTypeHint = $this->getMethodReturnType($methodReflection);
|
||||
}
|
||||
|
||||
if (empty($lazyPublicProperties) && ! $hasParentIsset) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$inheritDoc = $hasParentIsset ? '{@inheritDoc}' : '';
|
||||
$magicIsset = <<<EOT
|
||||
/**
|
||||
* $inheritDoc
|
||||
* @param string \$name
|
||||
* @return boolean
|
||||
*/
|
||||
public function __isset($parametersString)$returnTypeHint
|
||||
{
|
||||
|
||||
EOT;
|
||||
|
||||
if (! empty($lazyPublicProperties)) {
|
||||
$magicIsset .= <<<'EOT'
|
||||
if (\array_key_exists($name, self::$lazyPropertiesNames)) {
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', [$name]);
|
||||
|
||||
return isset($this->$name);
|
||||
}
|
||||
|
||||
|
||||
EOT;
|
||||
}
|
||||
|
||||
if ($hasParentIsset) {
|
||||
$magicIsset .= <<<'EOT'
|
||||
$this->__initializer__ && $this->__initializer__->__invoke($this, '__isset', [$name]);
|
||||
|
||||
return parent::__isset($name);
|
||||
EOT;
|
||||
} else {
|
||||
$magicIsset .= ' return false;';
|
||||
}
|
||||
|
||||
return $magicIsset . "\n }";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates implementation for the `__sleep` method of proxies.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateSleepImpl(ClassMetadata $class)
|
||||
{
|
||||
$reflectionClass = $class->getReflectionClass();
|
||||
|
||||
$hasParentSleep = $reflectionClass->hasMethod('__sleep');
|
||||
$inheritDoc = $hasParentSleep ? '{@inheritDoc}' : '';
|
||||
$returnTypeHint = $hasParentSleep ? $this->getMethodReturnType($reflectionClass->getMethod('__sleep')) : '';
|
||||
$sleepImpl = <<<EOT
|
||||
/**
|
||||
* $inheritDoc
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()$returnTypeHint
|
||||
{
|
||||
|
||||
EOT;
|
||||
|
||||
if ($hasParentSleep) {
|
||||
return $sleepImpl . <<<'EOT'
|
||||
$properties = array_merge(['__isInitialized__'], parent::__sleep());
|
||||
|
||||
if ($this->__isInitialized__) {
|
||||
$properties = array_diff($properties, array_keys(self::$lazyPropertiesNames));
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
EOT;
|
||||
}
|
||||
|
||||
$allProperties = ['__isInitialized__'];
|
||||
|
||||
foreach ($class->getReflectionClass()->getProperties() as $prop) {
|
||||
assert($prop instanceof ReflectionProperty);
|
||||
if ($prop->isStatic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$allProperties[] = $prop->isPrivate()
|
||||
? "\0" . $prop->getDeclaringClass()->getName() . "\0" . $prop->getName()
|
||||
: $prop->getName();
|
||||
}
|
||||
|
||||
$lazyPublicProperties = $this->getLazyLoadedPublicPropertiesNames($class);
|
||||
$protectedProperties = array_diff($allProperties, $lazyPublicProperties);
|
||||
|
||||
foreach ($allProperties as &$property) {
|
||||
$property = var_export($property, true);
|
||||
}
|
||||
|
||||
foreach ($protectedProperties as &$property) {
|
||||
$property = var_export($property, true);
|
||||
}
|
||||
|
||||
$allProperties = implode(', ', $allProperties);
|
||||
$protectedProperties = implode(', ', $protectedProperties);
|
||||
|
||||
return $sleepImpl . <<<EOT
|
||||
if (\$this->__isInitialized__) {
|
||||
return [$allProperties];
|
||||
}
|
||||
|
||||
return [$protectedProperties];
|
||||
}
|
||||
EOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates implementation for the `__wakeup` method of proxies.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateWakeupImpl(ClassMetadata $class)
|
||||
{
|
||||
$reflectionClass = $class->getReflectionClass();
|
||||
|
||||
$hasParentWakeup = $reflectionClass->hasMethod('__wakeup');
|
||||
|
||||
$unsetPublicProperties = [];
|
||||
foreach ($this->getLazyLoadedPublicPropertiesNames($class) as $lazyPublicProperty) {
|
||||
$unsetPublicProperties[] = '$this->' . $lazyPublicProperty;
|
||||
}
|
||||
|
||||
$shortName = $this->generateProxyShortClassName($class);
|
||||
$inheritDoc = $hasParentWakeup ? '{@inheritDoc}' : '';
|
||||
$returnTypeHint = $hasParentWakeup ? $this->getMethodReturnType($reflectionClass->getMethod('__wakeup')) : '';
|
||||
$wakeupImpl = <<<EOT
|
||||
/**
|
||||
* $inheritDoc
|
||||
*/
|
||||
public function __wakeup()$returnTypeHint
|
||||
{
|
||||
if ( ! \$this->__isInitialized__) {
|
||||
\$this->__initializer__ = function ($shortName \$proxy) {
|
||||
\$proxy->__setInitializer(null);
|
||||
\$proxy->__setCloner(null);
|
||||
|
||||
\$existingProperties = get_object_vars(\$proxy);
|
||||
|
||||
foreach (\$proxy::\$lazyPropertiesDefaults as \$property => \$defaultValue) {
|
||||
if ( ! array_key_exists(\$property, \$existingProperties)) {
|
||||
\$proxy->\$property = \$defaultValue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
EOT;
|
||||
|
||||
if (! empty($unsetPublicProperties)) {
|
||||
$wakeupImpl .= "\n unset(" . implode(', ', $unsetPublicProperties) . ');';
|
||||
}
|
||||
|
||||
$wakeupImpl .= "\n }";
|
||||
|
||||
if ($hasParentWakeup) {
|
||||
$wakeupImpl .= "\n parent::__wakeup();";
|
||||
}
|
||||
|
||||
$wakeupImpl .= "\n }";
|
||||
|
||||
return $wakeupImpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates implementation for the `__clone` method of proxies.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateCloneImpl(ClassMetadata $class)
|
||||
{
|
||||
$reflectionClass = $class->getReflectionClass();
|
||||
$hasParentClone = $reflectionClass->hasMethod('__clone');
|
||||
$returnTypeHint = $hasParentClone ? $this->getMethodReturnType($reflectionClass->getMethod('__clone')) : '';
|
||||
$inheritDoc = $hasParentClone ? '{@inheritDoc}' : '';
|
||||
$callParentClone = $hasParentClone ? "\n parent::__clone();\n" : '';
|
||||
|
||||
return <<<EOT
|
||||
/**
|
||||
* $inheritDoc
|
||||
*/
|
||||
public function __clone()$returnTypeHint
|
||||
{
|
||||
\$this->__cloner__ && \$this->__cloner__->__invoke(\$this, '__clone', []);
|
||||
$callParentClone }
|
||||
EOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates decorated methods by picking those available in the parent class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateMethods(ClassMetadata $class)
|
||||
{
|
||||
$methods = '';
|
||||
$methodNames = [];
|
||||
$reflectionMethods = $class->getReflectionClass()->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
$skippedMethods = [
|
||||
'__sleep' => true,
|
||||
'__clone' => true,
|
||||
'__wakeup' => true,
|
||||
'__get' => true,
|
||||
'__set' => true,
|
||||
'__isset' => true,
|
||||
];
|
||||
|
||||
foreach ($reflectionMethods as $method) {
|
||||
$name = $method->getName();
|
||||
|
||||
if (
|
||||
$method->isConstructor() ||
|
||||
isset($skippedMethods[strtolower($name)]) ||
|
||||
isset($methodNames[$name]) ||
|
||||
$method->isFinal() ||
|
||||
$method->isStatic() ||
|
||||
( ! $method->isPublic())
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$methodNames[$name] = true;
|
||||
$methods .= "\n /**\n"
|
||||
. " * {@inheritDoc}\n"
|
||||
. " */\n"
|
||||
. ' public function ';
|
||||
|
||||
if ($method->returnsReference()) {
|
||||
$methods .= '&';
|
||||
}
|
||||
|
||||
$methods .= $name . '(' . $this->buildParametersString($method->getParameters()) . ')';
|
||||
$methods .= $this->getMethodReturnType($method);
|
||||
$methods .= "\n" . ' {' . "\n";
|
||||
|
||||
if ($this->isShortIdentifierGetter($method, $class)) {
|
||||
$identifier = lcfirst(substr($name, 3));
|
||||
$fieldType = $class->getTypeOfField($identifier);
|
||||
$cast = in_array($fieldType, ['integer', 'smallint']) ? '(int) ' : '';
|
||||
|
||||
$methods .= ' if ($this->__isInitialized__ === false) {' . "\n";
|
||||
$methods .= ' ';
|
||||
$methods .= $this->shouldProxiedMethodReturn($method) ? 'return ' : '';
|
||||
$methods .= $cast . ' parent::' . $method->getName() . "();\n";
|
||||
$methods .= ' }' . "\n\n";
|
||||
}
|
||||
|
||||
$invokeParamsString = implode(', ', $this->getParameterNamesForInvoke($method->getParameters()));
|
||||
$callParamsString = implode(', ', $this->getParameterNamesForParentCall($method->getParameters()));
|
||||
|
||||
$methods .= "\n \$this->__initializer__ "
|
||||
. '&& $this->__initializer__->__invoke($this, ' . var_export($name, true)
|
||||
. ', [' . $invokeParamsString . ']);'
|
||||
. "\n\n "
|
||||
. ($this->shouldProxiedMethodReturn($method) ? 'return ' : '')
|
||||
. 'parent::' . $name . '(' . $callParamsString . ');'
|
||||
. "\n" . ' }' . "\n";
|
||||
}
|
||||
|
||||
return $methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the Proxy file name.
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $baseDirectory Optional base directory for proxy file name generation.
|
||||
* If not specified, the directory configured on the Configuration of the
|
||||
* EntityManager will be used by this factory.
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getProxyFileName($className, $baseDirectory = null)
|
||||
{
|
||||
$baseDirectory = $baseDirectory ?: $this->proxyDirectory;
|
||||
|
||||
return rtrim($baseDirectory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . Proxy::MARKER
|
||||
. str_replace('\\', '', $className) . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the method is a short identifier getter.
|
||||
*
|
||||
* What does this mean? For proxy objects the identifier is already known,
|
||||
* however accessing the getter for this identifier usually triggers the
|
||||
* lazy loading, leading to a query that may not be necessary if only the
|
||||
* ID is interesting for the userland code (for example in views that
|
||||
* generate links to the entity, but do not display anything else).
|
||||
*
|
||||
* @param ReflectionMethod $method
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isShortIdentifierGetter($method, ClassMetadata $class)
|
||||
{
|
||||
$identifier = lcfirst(substr($method->getName(), 3));
|
||||
$startLine = $method->getStartLine();
|
||||
$endLine = $method->getEndLine();
|
||||
$cheapCheck = $method->getNumberOfParameters() === 0
|
||||
&& substr($method->getName(), 0, 3) === 'get'
|
||||
&& in_array($identifier, $class->getIdentifier(), true)
|
||||
&& $class->hasField($identifier)
|
||||
&& ($endLine - $startLine <= 4);
|
||||
|
||||
if ($cheapCheck) {
|
||||
$code = file($method->getFileName());
|
||||
$code = trim(implode(' ', array_slice($code, $startLine - 1, $endLine - $startLine + 1)));
|
||||
|
||||
$pattern = sprintf(self::PATTERN_MATCH_ID_METHOD, $method->getName(), $identifier);
|
||||
|
||||
if (preg_match($pattern, $code)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the list of public properties to be lazy loaded.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function getLazyLoadedPublicPropertiesNames(ClassMetadata $class): array
|
||||
{
|
||||
$properties = [];
|
||||
|
||||
foreach ($class->getReflectionClass()->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
|
||||
$name = $property->getName();
|
||||
|
||||
if ((! $class->hasField($name) && ! $class->hasAssociation($name)) || $class->isIdentifier($name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$properties[] = $name;
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the list of default values of public properties.
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function getLazyLoadedPublicProperties(ClassMetadata $class)
|
||||
{
|
||||
$defaultProperties = $class->getReflectionClass()->getDefaultProperties();
|
||||
$lazyLoadedPublicProperties = $this->getLazyLoadedPublicPropertiesNames($class);
|
||||
$defaultValues = [];
|
||||
|
||||
foreach ($class->getReflectionClass()->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
|
||||
$name = $property->getName();
|
||||
|
||||
if (! in_array($name, $lazyLoadedPublicProperties, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (array_key_exists($name, $defaultProperties)) {
|
||||
$defaultValues[$name] = $defaultProperties[$name];
|
||||
} elseif (method_exists($property, 'getType')) {
|
||||
$propertyType = $property->getType();
|
||||
if ($propertyType !== null && $propertyType->allowsNull()) {
|
||||
$defaultValues[$name] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $defaultValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionParameter[] $parameters
|
||||
* @param string[] $renameParameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function buildParametersString(array $parameters, array $renameParameters = [])
|
||||
{
|
||||
$parameterDefinitions = [];
|
||||
|
||||
$i = -1;
|
||||
foreach ($parameters as $param) {
|
||||
assert($param instanceof ReflectionParameter);
|
||||
$i++;
|
||||
$parameterDefinition = '';
|
||||
$parameterType = $this->getParameterType($param);
|
||||
|
||||
if ($parameterType !== null) {
|
||||
$parameterDefinition .= $parameterType . ' ';
|
||||
}
|
||||
|
||||
if ($param->isPassedByReference()) {
|
||||
$parameterDefinition .= '&';
|
||||
}
|
||||
|
||||
if ($param->isVariadic()) {
|
||||
$parameterDefinition .= '...';
|
||||
}
|
||||
|
||||
$parameterDefinition .= '$' . ($renameParameters ? $renameParameters[$i] : $param->getName());
|
||||
$parameterDefinition .= $this->getParameterDefaultValue($param);
|
||||
|
||||
$parameterDefinitions[] = $parameterDefinition;
|
||||
}
|
||||
|
||||
return implode(', ', $parameterDefinitions);
|
||||
}
|
||||
|
||||
/** @return string|null */
|
||||
private function getParameterType(ReflectionParameter $parameter)
|
||||
{
|
||||
if (! $parameter->hasType()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$declaringFunction = $parameter->getDeclaringFunction();
|
||||
|
||||
assert($declaringFunction instanceof ReflectionMethod);
|
||||
|
||||
return $this->formatType($parameter->getType(), $declaringFunction, $parameter);
|
||||
}
|
||||
|
||||
/** @return string */
|
||||
private function getParameterDefaultValue(ReflectionParameter $parameter)
|
||||
{
|
||||
if (! $parameter->isDefaultValueAvailable()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID < 80100 || is_scalar($parameter->getDefaultValue())) {
|
||||
return ' = ' . var_export($parameter->getDefaultValue(), true);
|
||||
}
|
||||
|
||||
$value = rtrim(substr(explode('$' . $parameter->getName() . ' = ', (string) $parameter, 2)[1], 0, -2));
|
||||
|
||||
if (strpos($value, '\\') !== false || strpos($value, '::') !== false) {
|
||||
$value = preg_split("/('(?:[^'\\\\]*+(?:\\\\.)*+)*+')/", $value, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
foreach ($value as $i => $part) {
|
||||
if ($i % 2 === 0) {
|
||||
$value[$i] = preg_replace('/(?<![a-zA-Z0-9_\x7f-\xff\\\\])[a-zA-Z0-9_\x7f-\xff]++(?:\\\\[a-zA-Z0-9_\x7f-\xff]++|::)++/', '\\\\\0', $part);
|
||||
}
|
||||
}
|
||||
|
||||
$value = implode('', $value);
|
||||
}
|
||||
|
||||
return ' = ' . $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionParameter[] $parameters
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function getParameterNamesForInvoke(array $parameters)
|
||||
{
|
||||
return array_map(
|
||||
static function (ReflectionParameter $parameter) {
|
||||
return '$' . $parameter->getName();
|
||||
},
|
||||
$parameters
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionParameter[] $parameters
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function getParameterNamesForParentCall(array $parameters)
|
||||
{
|
||||
return array_map(
|
||||
static function (ReflectionParameter $parameter) {
|
||||
$name = '';
|
||||
|
||||
if ($parameter->isVariadic()) {
|
||||
$name .= '...';
|
||||
}
|
||||
|
||||
$name .= '$' . $parameter->getName();
|
||||
|
||||
return $name;
|
||||
},
|
||||
$parameters
|
||||
);
|
||||
}
|
||||
|
||||
/** @return string */
|
||||
private function getMethodReturnType(ReflectionMethod $method)
|
||||
{
|
||||
if (! $method->hasReturnType()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return ': ' . $this->formatType($method->getReturnType(), $method);
|
||||
}
|
||||
|
||||
/** @return bool */
|
||||
private function shouldProxiedMethodReturn(ReflectionMethod $method)
|
||||
{
|
||||
if (! $method->hasReturnType()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ! in_array(
|
||||
strtolower($this->formatType($method->getReturnType(), $method)),
|
||||
['void', 'never'],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/** @return string */
|
||||
private function formatType(
|
||||
ReflectionType $type,
|
||||
ReflectionMethod $method,
|
||||
?ReflectionParameter $parameter = null
|
||||
) {
|
||||
if ($type instanceof ReflectionUnionType) {
|
||||
return implode('|', array_map(
|
||||
function (ReflectionType $unionedType) use ($method, $parameter) {
|
||||
if ($unionedType instanceof ReflectionIntersectionType) {
|
||||
return '(' . $this->formatType($unionedType, $method, $parameter) . ')';
|
||||
}
|
||||
|
||||
return $this->formatType($unionedType, $method, $parameter);
|
||||
},
|
||||
$type->getTypes()
|
||||
));
|
||||
}
|
||||
|
||||
if ($type instanceof ReflectionIntersectionType) {
|
||||
return implode('&', array_map(
|
||||
function (ReflectionType $intersectedType) use ($method, $parameter) {
|
||||
return $this->formatType($intersectedType, $method, $parameter);
|
||||
},
|
||||
$type->getTypes()
|
||||
));
|
||||
}
|
||||
|
||||
assert($type instanceof ReflectionNamedType);
|
||||
|
||||
$name = $type->getName();
|
||||
$nameLower = strtolower($name);
|
||||
|
||||
if ($nameLower === 'static') {
|
||||
$name = 'static';
|
||||
}
|
||||
|
||||
if ($nameLower === 'self') {
|
||||
$name = $method->getDeclaringClass()->getName();
|
||||
}
|
||||
|
||||
if ($nameLower === 'parent') {
|
||||
$name = $method->getDeclaringClass()->getParentClass()->getName();
|
||||
}
|
||||
|
||||
if (! $type->isBuiltin() && ! class_exists($name) && ! interface_exists($name) && $name !== 'static') {
|
||||
if ($parameter !== null) {
|
||||
throw UnexpectedValueException::invalidParameterTypeHint(
|
||||
$method->getDeclaringClass()->getName(),
|
||||
$method->getName(),
|
||||
$parameter->getName()
|
||||
);
|
||||
}
|
||||
|
||||
throw UnexpectedValueException::invalidReturnTypeHint(
|
||||
$method->getDeclaringClass()->getName(),
|
||||
$method->getName()
|
||||
);
|
||||
}
|
||||
|
||||
if (! $type->isBuiltin() && $name !== 'static') {
|
||||
$name = '\\' . $name;
|
||||
}
|
||||
|
||||
if (
|
||||
$type->allowsNull()
|
||||
&& ! in_array($name, ['mixed', 'null'], true)
|
||||
&& ($parameter === null || ! $parameter->isDefaultValueAvailable() || $parameter->getDefaultValue() !== null)
|
||||
) {
|
||||
$name = '?' . $name;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
113
vendor/doctrine/common/src/Util/ClassUtils.php
vendored
Normal file
113
vendor/doctrine/common/src/Util/ClassUtils.php
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Util;
|
||||
|
||||
use Doctrine\Persistence\Proxy;
|
||||
use ReflectionClass;
|
||||
|
||||
use function get_class;
|
||||
use function get_parent_class;
|
||||
use function ltrim;
|
||||
use function rtrim;
|
||||
use function strrpos;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
* Class and reflection related functionality for objects that
|
||||
* might or not be proxy objects at the moment.
|
||||
*/
|
||||
class ClassUtils
|
||||
{
|
||||
/**
|
||||
* Gets the real class name of a class name that could be a proxy.
|
||||
*
|
||||
* @param string $className
|
||||
* @psalm-param class-string<Proxy<T>>|class-string<T> $className
|
||||
*
|
||||
* @return string
|
||||
* @psalm-return class-string<T>
|
||||
*
|
||||
* @template T of object
|
||||
*/
|
||||
public static function getRealClass($className)
|
||||
{
|
||||
$pos = strrpos($className, '\\' . Proxy::MARKER . '\\');
|
||||
|
||||
if ($pos === false) {
|
||||
/** @psalm-var class-string<T> */
|
||||
return $className;
|
||||
}
|
||||
|
||||
return substr($className, $pos + Proxy::MARKER_LENGTH + 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the real class name of an object (even if its a proxy).
|
||||
*
|
||||
* @param object $object
|
||||
* @psalm-param Proxy<T>|T $object
|
||||
*
|
||||
* @return string
|
||||
* @psalm-return class-string<T>
|
||||
*
|
||||
* @template T of object
|
||||
*/
|
||||
public static function getClass($object)
|
||||
{
|
||||
return self::getRealClass(get_class($object));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the real parent class name of a class or object.
|
||||
*
|
||||
* @param string $className
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return string
|
||||
* @psalm-return class-string
|
||||
*/
|
||||
public static function getParentClass($className)
|
||||
{
|
||||
return get_parent_class(self::getRealClass($className));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new reflection class.
|
||||
*
|
||||
* @param string $className
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return ReflectionClass
|
||||
*/
|
||||
public static function newReflectionClass($className)
|
||||
{
|
||||
return new ReflectionClass(self::getRealClass($className));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new reflection object.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return ReflectionClass
|
||||
*/
|
||||
public static function newReflectionObject($object)
|
||||
{
|
||||
return self::newReflectionClass(self::getClass($object));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a class name and a proxy namespace returns the proxy name.
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $proxyNamespace
|
||||
* @psalm-param class-string $className
|
||||
*
|
||||
* @return string
|
||||
* @psalm-return class-string
|
||||
*/
|
||||
public static function generateProxyClassName($className, $proxyNamespace)
|
||||
{
|
||||
return rtrim($proxyNamespace, '\\') . '\\' . Proxy::MARKER . '\\' . ltrim($className, '\\');
|
||||
}
|
||||
}
|
185
vendor/doctrine/common/src/Util/Debug.php
vendored
Normal file
185
vendor/doctrine/common/src/Util/Debug.php
vendored
Normal file
@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Util;
|
||||
|
||||
use ArrayIterator;
|
||||
use ArrayObject;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Persistence\Proxy;
|
||||
use stdClass;
|
||||
|
||||
use function array_keys;
|
||||
use function count;
|
||||
use function end;
|
||||
use function explode;
|
||||
use function extension_loaded;
|
||||
use function get_class;
|
||||
use function html_entity_decode;
|
||||
use function ini_get;
|
||||
use function ini_set;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function method_exists;
|
||||
use function ob_end_clean;
|
||||
use function ob_get_contents;
|
||||
use function ob_start;
|
||||
use function spl_object_hash;
|
||||
use function strip_tags;
|
||||
use function var_dump;
|
||||
|
||||
/**
|
||||
* Static class containing most used debug methods.
|
||||
*
|
||||
* @deprecated The Debug class is deprecated, please use symfony/var-dumper instead.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
*/
|
||||
final class Debug
|
||||
{
|
||||
/**
|
||||
* Private constructor (prevents instantiation).
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a dump of the public, protected and private properties of $var.
|
||||
*
|
||||
* @link https://xdebug.org/
|
||||
*
|
||||
* @param mixed $var The variable to dump.
|
||||
* @param int $maxDepth The maximum nesting level for object properties.
|
||||
* @param bool $stripTags Whether output should strip HTML tags.
|
||||
* @param bool $echo Send the dumped value to the output buffer
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function dump($var, $maxDepth = 2, $stripTags = true, $echo = true)
|
||||
{
|
||||
$html = ini_get('html_errors');
|
||||
|
||||
if ($html !== true) {
|
||||
ini_set('html_errors', 'on');
|
||||
}
|
||||
|
||||
if (extension_loaded('xdebug')) {
|
||||
ini_set('xdebug.var_display_max_depth', $maxDepth);
|
||||
}
|
||||
|
||||
$var = self::export($var, $maxDepth);
|
||||
|
||||
ob_start();
|
||||
var_dump($var);
|
||||
|
||||
$dump = ob_get_contents();
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
$dumpText = ($stripTags ? strip_tags(html_entity_decode($dump)) : $dump);
|
||||
|
||||
ini_set('html_errors', $html);
|
||||
|
||||
if ($echo) {
|
||||
echo $dumpText;
|
||||
}
|
||||
|
||||
return $dumpText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $var
|
||||
* @param int $maxDepth
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function export($var, $maxDepth)
|
||||
{
|
||||
$return = null;
|
||||
$isObj = is_object($var);
|
||||
|
||||
if ($var instanceof Collection) {
|
||||
$var = $var->toArray();
|
||||
}
|
||||
|
||||
if (! $maxDepth) {
|
||||
return is_object($var) ? get_class($var)
|
||||
: (is_array($var) ? 'Array(' . count($var) . ')' : $var);
|
||||
}
|
||||
|
||||
if (is_array($var)) {
|
||||
$return = [];
|
||||
|
||||
foreach ($var as $k => $v) {
|
||||
$return[$k] = self::export($v, $maxDepth - 1);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
if (! $isObj) {
|
||||
return $var;
|
||||
}
|
||||
|
||||
$return = new stdClass();
|
||||
if ($var instanceof DateTimeInterface) {
|
||||
$return->__CLASS__ = get_class($var);
|
||||
$return->date = $var->format('c');
|
||||
$return->timezone = $var->getTimezone()->getName();
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
$return->__CLASS__ = ClassUtils::getClass($var);
|
||||
|
||||
if ($var instanceof Proxy) {
|
||||
$return->__IS_PROXY__ = true;
|
||||
$return->__PROXY_INITIALIZED__ = $var->__isInitialized();
|
||||
}
|
||||
|
||||
if ($var instanceof ArrayObject || $var instanceof ArrayIterator) {
|
||||
$return->__STORAGE__ = self::export($var->getArrayCopy(), $maxDepth - 1);
|
||||
}
|
||||
|
||||
return self::fillReturnWithClassAttributes($var, $return, $maxDepth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the $return variable with class attributes
|
||||
* Based on obj2array function from {@see https://secure.php.net/manual/en/function.get-object-vars.php#47075}
|
||||
*
|
||||
* @param object $var
|
||||
* @param int $maxDepth
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function fillReturnWithClassAttributes($var, stdClass $return, $maxDepth)
|
||||
{
|
||||
$clone = (array) $var;
|
||||
|
||||
foreach (array_keys($clone) as $key) {
|
||||
$aux = explode("\0", $key);
|
||||
$name = end($aux);
|
||||
if ($aux[0] === '') {
|
||||
$name .= ':' . ($aux[1] === '*' ? 'protected' : $aux[1] . ':private');
|
||||
}
|
||||
|
||||
$return->$name = self::export($clone[$key], $maxDepth - 1);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of an object.
|
||||
*
|
||||
* @param object $obj
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function toString($obj)
|
||||
{
|
||||
return method_exists($obj, '__toString') ? (string) $obj : get_class($obj) . '@' . spl_object_hash($obj);
|
||||
}
|
||||
}
|
36
vendor/doctrine/data-fixtures/.doctrine-project.json
vendored
Normal file
36
vendor/doctrine/data-fixtures/.doctrine-project.json
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"active": true,
|
||||
"name": "Data fixtures",
|
||||
"slug": "data-fixtures",
|
||||
"docsSlug": "doctrine-data-fixtures",
|
||||
"versions": [
|
||||
{
|
||||
"name": "1.6",
|
||||
"branchName": "1.6.x",
|
||||
"slug": "1.6",
|
||||
"upcoming": true
|
||||
},
|
||||
{
|
||||
"name": "1.5",
|
||||
"branchName": "1.5.x",
|
||||
"slug": "latest",
|
||||
"current": true,
|
||||
"aliases": [
|
||||
"current",
|
||||
"stable"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "1.4",
|
||||
"branchName": "1.4.x",
|
||||
"slug": "1.4",
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "1.3",
|
||||
"branchName": "1.3",
|
||||
"slug": "1.3",
|
||||
"maintained": false
|
||||
}
|
||||
]
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user