master

laravel/framework

Last updated at: 29/12/2023 09:24

Dimensions.php

TLDR

This file defines a class called Dimensions in the Illuminate\Validation\Rules namespace. The class implements the Stringable interface and is used to create validation rules for dimensions of images or other types of media files.

Methods

constructor(array $constraints = [])

This method is the constructor for the Dimensions class. It takes an optional parameter $constraints which is an array of constraints for the dimensions rule.

width(int $value): Dimensions

This method is used to set the "width" constraint for the dimensions rule. It takes an integer parameter $value representing the width constraint and returns the current Dimensions instance.

height(int $value): Dimensions

This method is used to set the "height" constraint for the dimensions rule. It takes an integer parameter $value representing the height constraint and returns the current Dimensions instance.

minWidth(int $value): Dimensions

This method is used to set the "min width" constraint for the dimensions rule. It takes an integer parameter $value representing the min width constraint and returns the current Dimensions instance.

minHeight(int $value): Dimensions

This method is used to set the "min height" constraint for the dimensions rule. It takes an integer parameter $value representing the min height constraint and returns the current Dimensions instance.

maxWidth(int $value): Dimensions

This method is used to set the "max width" constraint for the dimensions rule. It takes an integer parameter $value representing the max width constraint and returns the current Dimensions instance.

maxHeight(int $value): Dimensions

This method is used to set the "max height" constraint for the dimensions rule. It takes an integer parameter $value representing the max height constraint and returns the current Dimensions instance.

ratio(float $value): Dimensions

This method is used to set the "ratio" constraint for the dimensions rule. It takes a float parameter $value representing the ratio constraint and returns the current Dimensions instance.

__toString(): string

This method is used to convert the rule to a validation string. It concatenates the constraints as a string representation of the dimensions rule.

Classes

There are no additional classes in this file.

<?php

namespace Illuminate\Validation\Rules;

use Illuminate\Support\Traits\Conditionable;
use Stringable;

class Dimensions implements Stringable
{
    use Conditionable;

    /**
     * The constraints for the dimensions rule.
     *
     * @var array
     */
    protected $constraints = [];

    /**
     * Create a new dimensions rule instance.
     *
     * @param  array  $constraints
     * @return void
     */
    public function __construct(array $constraints = [])
    {
        $this->constraints = $constraints;
    }

    /**
     * Set the "width" constraint.
     *
     * @param  int  $value
     * @return $this
     */
    public function width($value)
    {
        $this->constraints['width'] = $value;

        return $this;
    }

    /**
     * Set the "height" constraint.
     *
     * @param  int  $value
     * @return $this
     */
    public function height($value)
    {
        $this->constraints['height'] = $value;

        return $this;
    }

    /**
     * Set the "min width" constraint.
     *
     * @param  int  $value
     * @return $this
     */
    public function minWidth($value)
    {
        $this->constraints['min_width'] = $value;

        return $this;
    }

    /**
     * Set the "min height" constraint.
     *
     * @param  int  $value
     * @return $this
     */
    public function minHeight($value)
    {
        $this->constraints['min_height'] = $value;

        return $this;
    }

    /**
     * Set the "max width" constraint.
     *
     * @param  int  $value
     * @return $this
     */
    public function maxWidth($value)
    {
        $this->constraints['max_width'] = $value;

        return $this;
    }

    /**
     * Set the "max height" constraint.
     *
     * @param  int  $value
     * @return $this
     */
    public function maxHeight($value)
    {
        $this->constraints['max_height'] = $value;

        return $this;
    }

    /**
     * Set the "ratio" constraint.
     *
     * @param  float  $value
     * @return $this
     */
    public function ratio($value)
    {
        $this->constraints['ratio'] = $value;

        return $this;
    }

    /**
     * Convert the rule to a validation string.
     *
     * @return string
     */
    public function __toString()
    {
        $result = '';

        foreach ($this->constraints as $key => $value) {
            $result .= "$key=$value,";
        }

        return 'dimensions:'.substr($result, 0, -1);
    }
}