PHP Classes

File: src/Attributes/BoolAttr.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Parameter   src/Attributes/BoolAttr.php   Download  
File: src/Attributes/BoolAttr.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Parameter
Validate function parameters with PHP attributes
Author: By
Last change:
Date: 24 days ago
Size: 1,290 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
Chevere\Parameter\Interfaces\BoolParameterInterface;
use
Chevere\Parameter\Interfaces\ParameterAttributeInterface;
use
Chevere\Parameter\Interfaces\ParameterInterface;
use
Chevere\Parameter\Traits\AttrTrait;
use function
Chevere\Parameter\bool;

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

    private
BoolParameterInterface $parameter;

    public function
__construct(
       
string $description = '',
        ?
bool $default = null,
       
bool $sensitive = false
   
) {
       
$this->parameter = bool(
           
description: $description,
            default:
$default,
           
sensitive: $sensitive
       
);
    }

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

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