Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/allure-framework/allure-php-commons/src/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/allure-framework/allure-php-commons/src/Model/JsonSerializableTrait.php
<?php

declare(strict_types=1);

namespace Qameta\Allure\Model;

use JsonSerializable;

use function array_filter;
use function array_keys;
use function array_map;
use function get_object_vars;
use function in_array;
use function is_array;

use const ARRAY_FILTER_USE_KEY;

/**
 * This trait implements {@see JsonSerializable::jsonSerialize()} method and can be used to serialize model objects
 * before writing them to output directory.
 */
trait JsonSerializableTrait
{
    /**
     * Returns JSON object that has all properties (except for those listed by {@see excludeFromSerialization()})
     * with {@see prepareForSerialization()} results as values.
     *
     * @return array
     * @see JsonSerializable
     */
    final public function jsonSerialize(): array
    {
        $includedProperties = array_filter(
            get_object_vars($this),
            fn (string $key): bool => !in_array($key, $this->excludeFromSerialization(), true),
            ARRAY_FILTER_USE_KEY,
        );

        $propertyKeys = array_keys($includedProperties);
        $preparedProperties = array_map(
            fn (string $propertyName, mixed $property): mixed => $this->prepareForSerialization(
                $propertyName,
                $property,
            ),
            $propertyKeys,
            $includedProperties,
        );

        return array_map(
            static fn (mixed $property): mixed => is_array($property)
                ? array_filter(
                    $property,
                    static fn(mixed $propertyItem): bool =>
                        !$propertyItem instanceof ResultInterface ||
                        !$propertyItem->getExcluded(),
                )
                : $property,
            array_combine($propertyKeys, $preparedProperties),
        );
    }

    /**
     * Put property name to this list to exclude it from serialization.
     *
     * @return list<string>
     */
    protected function excludeFromSerialization(): array
    {
        return [];
    }

    /**
     * Override this method to replace serialized value for specific properties.
     *
     * @noinspection PhpUnusedParameterInspection
     */
    protected function prepareForSerialization(string $propertyName, mixed $property): mixed
    {
        return $property;
    }
}

Spamworldpro Mini