PHP Classes

File: src/Attributes/StringAttr.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Parameter   src/Attributes/StringAttr.php   Download  
File: src/Attributes/StringAttr.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Parameter
Validate function parameters with PHP attributes
Author: By
Last change:
Date: 15 days ago
Size: 1,332 bytes
 

Contents

Class file image Download
<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace
Chevere\Parameter\Attributes;

use
Attribute;
use
BackedEnum;
use
Chevere\Parameter\Interfaces\ParameterAttributeInterface;
use
Chevere\Parameter\Interfaces\ParameterInterface;
use
Chevere\Parameter\Interfaces\StringParameterInterface;
use
Chevere\Parameter\Traits\AttrTrait;
use function
Chevere\Parameter\string;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER | Attribute::TARGET_CLASS_CONSTANT)]
class StringAttr implements ParameterAttributeInterface
{
    use
AttrTrait;

    private
StringParameterInterface $parameter;

    public function
__construct(
       
string|BackedEnum $pattern = '',
       
string $description = '',
       
bool $sensitive = false
   
) {
       
$this->parameter = string(
           
regex: $pattern,
           
description: $description,
           
sensitive: $sensitive
       
);
    }

    public function
__invoke(string $string): string
   
{
        return
$this->parameter->__invoke($string);
    }

    public function
parameter(): ParameterInterface
   
{
        return
$this->parameter;
    }
}