PHP Classes

File: src/ArrayStringParameter.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Parameter   src/ArrayStringParameter.php   Download  
File: src/ArrayStringParameter.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Parameter
Validate function parameters with PHP attributes
Author: By
Last change:
Date: 20 days ago
Size: 1,531 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;

use
Chevere\Parameter\Interfaces\ArrayStringParameterInterface;
use
Chevere\Parameter\Interfaces\StringParameterInterface;
use
Chevere\Parameter\Traits\ArrayParameterModifyTrait;
use
Chevere\Parameter\Traits\ArrayParameterTrait;
use
Chevere\Parameter\Traits\ParameterAssertArrayTypeTrait;
use
Chevere\Parameter\Traits\ParameterTrait;

final class
ArrayStringParameter implements ArrayStringParameterInterface
{
    use
ArrayParameterTrait;
    use
ArrayParameterModifyTrait;
    use
ParameterAssertArrayTypeTrait;
    use
ParameterTrait;

   
/**
     * @var array<mixed, string>
     */
   
private ?array $default = null;

    public function
setUp(): void
   
{
       
$this->parameters = new Parameters();
    }

    public function
withRequired(StringParameterInterface ...$parameter): static
    {
       
$new = clone $this;
       
$new->put('withRequired', ...$parameter);

        return
$new;
    }

    public function
withOptional(StringParameterInterface ...$parameter): static
    {
       
$new = clone $this;
       
$new->put('withOptional', ...$parameter);

        return
$new;
    }

    public function
assertCompatible(ArrayStringParameterInterface $parameter): void
   
{
       
$this->assertArrayType($parameter);
    }
}