Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips
System : Linux server1.richineiserver.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User : fdshops ( 1003)
PHP Version : 8.2.21
Disable Function : NONE
Directory :  /home/fdshops/public_html/vendor/knuckleswtf/scribe/src/Attributes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/fdshops/public_html/vendor/knuckleswtf/scribe/src/Attributes/GenericParam.php
<?php

namespace Knuckles\Scribe\Attributes;

use Attribute;

#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
class GenericParam
{
    public function __construct(
        public string $name,
        public ?string $type = 'string',
        public ?string $description = '',
        public ?bool $required = true,
        public mixed $example = null, /* Pass 'No-example' to omit the example */
        public mixed $enum = null, // Can pass a list of values, or a native PHP enum
    ) {
    }

    public function toArray()
    {
        return [
            "name" => $this->name,
            "description" => $this->description,
            "type" => $this->type,
            "required" => $this->required,
            "example" => $this->example,
            "enumValues" => $this->getEnumValues(),
        ];
    }

    protected function getEnumValues(): array
    {
        if (!$this->enum) {
            return [];
        }

        if (is_array($this->enum)) {
            return $this->enum;
        }

        if (function_exists('enum_exists') && enum_exists($this->enum)
            && method_exists($this->enum, 'tryFrom')
        ) {
            return array_map(
            // $case->value only exists on BackedEnums, not UnitEnums
            // method_exists($enum, 'tryFrom') implies $enum instanceof BackedEnum
            // @phpstan-ignore-next-line
                fn ($case) => $case->value,
                $this->enum::cases()
            );
        }

        throw new \InvalidArgumentException(
            'The enum property of a parameter must be either a PHP enum or an array of values'
        );
    }
}

Spamworldpro Mini