Initial commit: WordPress wp-content (themes, plugins, languages)

- Theme: momentry (custom theme with REST API routes)
- Plugins: code-snippets (contains all API proxies)
- Languages: zh_TW translations
- Excludes: cache, backups, uploads, logs
This commit is contained in:
OpenCode
2026-05-29 19:07:56 +08:00
commit 09ef1f000f
6521 changed files with 867163 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
Open Software License v. 3.0 (OSL-3.0)
This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work:
Licensed under the Open Software License version 3.0
1) Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:
a) to reproduce the Original Work in copies, either alone or as part of a collective work;
b) to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work;
c) to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License;
d) to perform the Original Work publicly; and
e) to display the Original Work publicly.
2) Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.
4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensors trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.
5) External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).
6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.
8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.
9) Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including “fair use” or “fair dealing”). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).
10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.
12) Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
13) Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
16) Modification of This License. This License is Copyright (c) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.

View File

@@ -0,0 +1,15 @@
<?php
namespace WPForms\Vendor;
class Address
{
public $street;
public $city;
public function getGeoCoords()
{
$data = \file_get_contents('http://nominatim.openstreetmap.org/search?q=' . \urlencode($this->street) . ',' . \urlencode($this->city) . '&format=json&addressdetails=1');
$json = \json_decode($data);
return array('lat' => $json[0]->lat, 'lon' => $json[0]->lon);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace WPForms\Vendor;
class Contact
{
public $name;
/**
* @var Address
*/
public $address;
}

View File

@@ -0,0 +1,12 @@
<?php
namespace WPForms\Vendor;
require_once __DIR__ . '/../src/JsonMapper.php';
require_once 'Contact.php';
require_once 'Address.php';
$json = \json_decode(\file_get_contents(__DIR__ . '/single.json'));
$mapper = new JsonMapper();
$contact = $mapper->map($json, new Contact());
$coords = $contact->address->getGeoCoords();
echo $contact->name . ' lives at coordinates ' . $coords['lat'] . ',' . $coords['lon'] . "\n";

View File

@@ -0,0 +1,39 @@
<?php
/**
* Part of JsonMapper
*
* PHP version 5
*
* @category Apimatic
* @package JsonMapper
* @author Asad Ali <asad.ali@apimatic.io>
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
* @link https://www.apimatic.io/
*/
namespace WPForms\Vendor\apimatic\jsonmapper;
/**
* OneOf Validation Exception.
*
* @category Apimatic
* @package JsonMapper
* @author Asad Ali <asad.ali@apimatic.io>
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
* @link https://www.apimatic.io/
*/
class AnyOfValidationException extends JsonMapperException
{
/**
* JSON does not match any of the types provided.
*
* @param string $type The type JSON could not be mapped to.
* @param string $json JSON string.
*
* @return AnyOfValidationException
*/
static function cannotMapAnyOfException($type, $json)
{
return new self("We could not match any acceptable type from" . " {$type} on: {$json}");
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,153 @@
<?php
/**
* Part of JsonMapper
*
* PHP version 5
*
* @category Netresearch
* @package JsonMapper
* @author Christian Weiske <christian.weiske@netresearch.de>
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
* @link http://www.netresearch.de/
*/
namespace WPForms\Vendor\apimatic\jsonmapper;
use RuntimeException;
/**
* Simple exception
*
* @category Netresearch
* @package JsonMapper
* @author Christian Weiske <christian.weiske@netresearch.de>
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
* @link http://www.netresearch.de/
*/
class JsonMapperException extends RuntimeException
{
/**
* Exception for discarded comments setting in configuration.
*
* @param array $concernedKeys Keys (PHP directives) with issues.
*
* @return JsonMapperException
*/
static function commentsDisabledInConfigurationException($concernedKeys)
{
return new self("Comments cannot be discarded in the configuration file i.e." . " the php.ini file; doc comments are a requirement for JsonMapper." . " Following configuration keys must have a value set to \"1\": " . \implode(", ", $concernedKeys) . ".");
}
/**
* Exception for non-existent key in an object.
*
* @param string $key The missing key/property.
* @param string $class The class in which the key is missing.
* @param bool $setterException Raise an exception specific to
* missing a setter within the class for
* the specified string.
*
* @return JsonMapperException
*/
static function undefinedPropertyException($key, $class, $setterException = \false)
{
$err = $setterException ? 'has no public setter method' : 'does not exist';
return new self("JSON property '{$key}' {$err} in object of type '{$class}'");
}
/**
* Exception for non-existent key in an object.
*
* @param string $key The property missing type.
* @param string $strClassName The class in which the property is missing type.
*
* @return JsonMapperException
*/
static function missingTypePropertyException($key, $strClassName)
{
return new self("Empty type at property '{$strClassName}::\${$key}'");
}
/**
* Exception for an unCallable Factory Method.
*
* @param string $factoryMethod The concerned factory method.
* @param string $strClassName Related class name.
*
* @return JsonMapperException
*/
static function unCallableFactoryMethodException($factoryMethod, $strClassName)
{
return new self("Factory method '{$factoryMethod}' referenced by " . "'{$strClassName}' is not callable.");
}
/**
* Exception for not able to call factory method with the given value.
*
* @param string $argType Type of the argument passed in method.
* @param string $reasons Exception message received from factory method.
*
* @return JsonMapperException
*/
static function invalidArgumentFactoryMethodException($argType, $reasons)
{
return new self("Provided factory methods are not callable with " . "the value of Type: {$argType}\n{$reasons}");
}
/**
* Exception when it is not possible to map an object to a specific type.
*
* @param string $typeName Name of type to map json object on.
* @param string $typeGroup Group name of the type provided.
* @param string $value Value that should be mapped by typeGroup
* i.e. JSON string.
*
* @return JsonMapperException
*/
static function unableToMapException($typeName, $typeGroup, $value)
{
return new self("Unable to map {$typeName}: {$typeGroup} on: {$value}");
}
/**
* A property marked as required was missing in the object provided.
*
* @param string $propertyName Concerned property's name.
* @param string $className The class name in which the property wasn't found.
*
* @return JsonMapperException
*/
static function requiredPropertyMissingException($propertyName, $className)
{
return new self("Required property '{$propertyName}' of class " . "'{$className}' is missing in JSON data");
}
/**
* No required arguments were provided.
*
* @param string $class The concerned class name.
* @param int $ctorReqParamNumber The number of req params in constructor.
*
* @return JsonMapperException
*/
static function noArgumentsException($class, $ctorReqParamNumber)
{
return new self("{$class} class requires {$ctorReqParamNumber} " . "arguments in constructor but none provided");
}
/**
* Provided arguments were less than required.
*
* @param string $class The concerned class name.
* @param array $ctorRequiredParamsName Required parameters array.
*
* @return JsonMapperException
*/
static function fewerArgumentsException($class, $ctorRequiredParamsName)
{
return new self("Could not find required constructor arguments for {$class}: " . \implode(", ", $ctorRequiredParamsName));
}
/**
* Provided type was not applicable on the given value.
*
* @param string $type The type value could not be mapped to.
* @param string $value Concerned value.
*
* @return JsonMapperException
*/
static function unableToSetTypeException($type, $value)
{
return new self("Could not set type '{$type}' on value: {$value}");
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Part of JsonMapper
*
* PHP version 5
*
* @category Apimatic
* @package JsonMapper
* @author Asad Ali <asad.ali@apimatic.io>
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
* @link https://www.apimatic.io/
*/
namespace WPForms\Vendor\apimatic\jsonmapper;
/**
* OneOf Validation Exception.
*
* @category Apimatic
* @package JsonMapper
* @author Asad Ali <asad.ali@apimatic.io>
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
* @link https://www.apimatic.io/
*/
class OneOfValidationException extends JsonMapperException
{
/**
* Exception raised when a json object maps to more
* than one type within the types specified in OneOf.
*
* @param string $matchedType First type.
* @param string $mappedWith Second type.
* @param string $json JSON string.
*
* @return OneOfValidationException
*/
static function moreThanOneOfException($matchedType, $mappedWith, $json)
{
return new self("There are more than one matching types i.e." . " { {$matchedType} and {$mappedWith} } on: {$json}");
}
/**
* JSON does not match any of the provided types.
*
* @param string $type The type JSON could not be mapped to.
* @param string $json JSON string.
*
* @return OneOfValidationException
*/
static function cannotMapAnyOfException($type, $json)
{
return new self("We could not match any acceptable type from" . " {$type} on: {$json}");
}
}

View File

@@ -0,0 +1,393 @@
<?php
/**
* Part of JsonMapper
*
* PHP version 5
*
* @category Apimatic
* @package JsonMapper
* @author Asad Ali <asad.ali@apimatic.io>
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
* @link https://www.apimatic.io/
*/
namespace WPForms\Vendor\apimatic\jsonmapper;
/**
* Data class to hold the groups of multiple types.
*
* @category Apimatic
* @package JsonMapper
* @author Asad Ali <asad.ali@apimatic.io>
* @license OSL-3.0 http://opensource.org/licenses/osl-3.0
* @link https://www.apimatic.io/
*/
class TypeCombination
{
/**
* String format of this typeCombinator group.
*
* @var string
*/
private $_format;
/**
* Name of this typeCombinator group i.e. oneOf/anyOf.
*
* @var string
*/
private $_groupName;
/**
* Name of discriminator field for this typeCombinator group.
*
* @var string
*/
private $_discriminatorField;
/**
* Mapping of each discriminator value on types in this typeCombinator group.
* i.e. [typeName => discriminatorValues]
*
* @var array
*/
private $_discriminatorMapping = [];
/**
* Array of string types or TypeCombination objects
*
* @var array
*/
private $_types;
/**
* A list of factory methods to deserialize the given object,
* for one of the wrapped types in this group
*
* @var string[]
*/
private $_deserializers;
/**
* Private constructor for TypeCombination class
*
* @param string $format string format value
* @param string $groupName group name value
* @param array $types types value
* @param string[] $deserializers deserializers value
*/
private function __construct($format, $groupName, $types, $deserializers)
{
$this->_format = $format;
$this->_groupName = $groupName;
$this->_types = $types;
$this->_deserializers = $deserializers;
$this->_insertDiscriminators();
}
/**
* String format of this typeCombinator group.
*
* @return string
*/
public function getFormat()
{
return $this->_format;
}
/**
* Name of this typeCombinator group i.e. oneOf/anyOf/array/map.
*
* @return string
*/
public function getGroupName()
{
return $this->_groupName;
}
/**
* Array of string types or TypeCombination objects
*
* @return array
*/
public function getTypes()
{
return $this->_types;
}
/**
* A list of factory methods to deserialize the given object,
* for one of the wrapped types in this group
*
* @return string[]
*/
public function getDeserializers()
{
return $this->_deserializers;
}
/**
* Get discriminator info as an array (if exists)
*
* @param string $type String type to search
* discriminators
* @param array<string,string> $discriminatorSubs Map of actual discriminator
* values where keys contain
* substituted values in the
* typeGroup string, Default: []
*
* @return array|null An array with format: discriminatorFieldName
* as element 1 and discriminatorValues as
* element 2
*/
public function getDiscriminator($type, $discriminatorSubs = [])
{
if (!isset($this->_discriminatorField) || !isset($this->_discriminatorMapping[$type])) {
return null;
}
$fieldName = $this->_discriminatorField;
if (isset($discriminatorSubs[$fieldName])) {
$fieldName = $discriminatorSubs[$fieldName];
}
$discValues = \array_map(function ($value) use($discriminatorSubs) {
if (isset($discriminatorSubs[$value])) {
return $discriminatorSubs[$value];
}
return $value;
}, $this->_discriminatorMapping[$type]);
return [$fieldName, $discValues];
}
/**
* Extract innermost oneof/anyof group hidden inside array/map
* type group
*
* @return TypeCombination
*/
public function extractOneOfAnyOfGroup()
{
$innerType = $this->getTypes()[0];
if (\in_array($this->getGroupName(), ["array", "map"]) && $innerType instanceof TypeCombination) {
return $innerType->extractOneOfAnyOfGroup();
}
return $this;
}
/**
* Extract all internal groups similar to the given group as a list of
* TypeCombination objects, it will only return similar array/map groups
*
* @param TypeCombination $group All inner groups similar to this array/map
* type group will be extracted
*
* @return TypeCombination[] A list of similar TypeCombination objects
*/
public function extractSimilar($group)
{
$result = [];
if (!\in_array($this->getGroupName(), ["array", "map"])) {
// if group is neither array nor map then call extractSimilar for
// each of the internal groups
foreach ($this->getTypes() as $typ) {
if ($typ instanceof TypeCombination) {
$result = \array_merge($result, $typ->extractSimilar($group));
}
}
} elseif ($group->getGroupName() == $this->getGroupName()) {
// if groupName is same then check inner group type
$internal = $this->getTypes()[0];
$group = $group->getTypes()[0];
if (\in_array($group->getGroupName(), ["array", "map"])) {
// if inner group is array/map then return result after
// extraction of groups similar to innerGroup
$result = $internal->extractSimilar($group);
} else {
// if inner group is oneof/anyof then only extract $internal
$result = [$internal];
}
}
return $result;
}
/**
* Extract type info like: isMap, isArray, and inner type for maps/arrays.
*
* @param string $type Type to be checked and extracted for information.
*
* @return array An array with type info in the format:
* (bool isMap, bool isArray, string $internalType).
*/
public static function extractTypeInfo($type)
{
// Check if the type is map, i.e. wrapped in array<string,...>
if (\preg_match('/^array<string,.*>$/', $type)) {
return [\true, \false, \substr($type, \strlen('array<string,'), -1)];
}
// Check if the type is array, i.e. ends with '[]'
if (\preg_match('/\\[]$/', $type)) {
return [\false, \true, \substr($type, 0, -2)];
}
// Check if the type is array, i.e. wrapped in 'array<...>'
if (\preg_match('/^array<.*>$/', $type)) {
return [\false, \true, \substr($type, \strlen('array<'), -1)];
}
// If the type does not match the array formats, return the original type
return [\false, \false, $type];
}
/**
* Create an oneof/anyof TypeCombination instance, by specifying inner types
*
* @param array $types i.e. (TypeCombination,string)[]
* @param string $gName group name value (anyof, oneof),
* Default: anyof
*
* @return TypeCombination
*/
public static function with($types, $gName = 'anyof')
{
$format = \join(',', \array_map(function ($t) {
return \is_string($t) ? $t : $t->getFormat();
}, $types));
return new self("{$gName}({$format})", $gName, $types, []);
}
/**
* Wrap the given typeGroup string in the TypeCombination class,
* i.e. getTypes() method will return all the grouped types,
* while deserializing factory methods can be obtained by
* getDeserializers() and group name can be obtained from getGroupName()
*
* @param string $typeGroup Format of multiple types i.e oneOf(int,bool)[],
* onyOf(int[], bool,anyOf(string,float)[],...),
* array<string,oneOf(int,float)[]> here []
* represents array types, and array<string,T>
* represents map types, oneOf/anyOf are group
* names, while default group name is anyOf.
* @param string[] $deserializers Callable factory methods for the property,
* Default: []
*
* @return TypeCombination
*/
public static function withFormat($typeGroup, $deserializers = [])
{
$groupName = 'anyOf';
$start = \strpos($typeGroup, '(');
$end = \strrpos($typeGroup, ')');
if ($start !== \false && $end !== \false) {
list($isMap, $isArray, $innerType) = self::extractTypeInfo($typeGroup);
if ($isMap || $isArray) {
return self::_createTypeGroup($isMap ? 'map' : 'array', $innerType, $deserializers);
}
$name = \substr($typeGroup, 0, $start);
$groupName = empty($name) ? $groupName : $name;
$typeGroup = \substr($typeGroup, $start + 1, -1);
}
$format = "({$typeGroup})";
$types = [];
$type = '';
$groupCount = 0;
foreach (\str_split($typeGroup) as $c) {
if ($c == '(' || $c == '<') {
$groupCount++;
}
if ($c == ')' || $c == '>') {
$groupCount--;
}
if ($c == ',' && $groupCount == 0) {
self::_insertType($types, $type, $deserializers);
$type = '';
continue;
}
$type .= $c;
}
self::_insertType($types, $type, $deserializers);
return new self($format, $groupName, $types, $deserializers);
}
/**
* Creates a TypeCombination object with the given name and inner
* types group that must be another typeCombination object
*
* @param string $name Group name for the typeCombination object.
* @param string $type typeGroup to be created and inserted.
* @param string[] $deserializers deserializer for the type group.
*
* @return TypeCombination
*/
private static function _createTypeGroup($name, $type, $deserializers)
{
$format = $name == 'map' ? "array<string,{$type}>" : $type . '[]';
return new self($format, $name, [self::withFormat($type, $deserializers)], $deserializers);
}
/**
* Insert the type in the types array which is passed by reference,
* Also check if type is not empty
*
* @param array $types types array reference
* @param string $type type to be inserted
* @param string[] $deserializers deserializer for the type group
*
* @return void
*/
private static function _insertType(&$types, $type, $deserializers)
{
$type = \trim($type);
if (\strpos($type, '(') !== \false && \strrpos($type, ')') !== \false) {
// If type is Grouped, creating TypeCombination instance for it
$type = self::withFormat($type, $deserializers);
}
if (!empty($type)) {
$types[] = $type;
}
}
/**
* Insert discriminator and discriminators mapping from group and
* type names.
*
* @return void
*/
private function _insertDiscriminators()
{
list($this->_groupName, $this->_discriminatorField) = self::_extractDiscriminator($this->_groupName);
$this->_types = $this->_filterUniqueTypes(\array_map(function ($type) {
if (!\is_string($type)) {
return $type;
}
list($type, $discriminator) = self::_extractDiscriminator($type);
if (\array_key_exists($type, $this->_discriminatorMapping)) {
$this->_discriminatorMapping[$type][] = $discriminator;
} else {
$this->_discriminatorMapping[$type] = [$discriminator];
}
return $type;
}, $this->_types));
if (isset($this->_discriminatorField)) {
$this->_format .= '{' . $this->_discriminatorField . '}';
}
}
/**
* Filter out the same types.
*
* @param array $types Types to be checked for uniqueness.
*
* @return array An array with all the unique types
*/
private function _filterUniqueTypes($types)
{
$seenTypes = [];
$uniqueTypes = [];
foreach ($types as $type) {
if (\is_string($type)) {
if (\in_array($type, $seenTypes, \true)) {
continue;
}
$seenTypes[] = $type;
}
$uniqueTypes[] = $type;
}
return $uniqueTypes;
}
/**
* Extract type discriminator.
*
* @param string $type Type to be checked and extracted for discriminator.
*
* @return array An array with type info in the format:
* (string $typeWithoutDiscriminator, string? discriminator).
*/
private function _extractDiscriminator($type)
{
$start = \strpos($type, '{');
$end = \strpos($type, '}');
$discriminator = null;
if ($start !== \false && $end !== \false) {
$discriminator = \substr($type, $start + 1, $end - \strlen($type));
$type = \substr($type, 0, $start) . \substr($type, $end + 1);
}
return [$type, $discriminator];
}
}