Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Validator] AddVideo constraint for validating video files#59042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
symfonyaml wants to merge16 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromsymfonyaml:video-validator
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
f6b9168
[Validator] Add the Video constraint for validating video files
Nov 29, 2024
c670298
Fix conflicts in CHANGELOG
Nov 29, 2024
5b6f30a
Update uuid and add comments
Nov 29, 2024
9b9928f
Apply coding standards suggested by fabbot.io
Nov 29, 2024
ed02046
Use ::class whenever possible from fabbot.io
Nov 29, 2024
21e0c7a
php-ffmpeg in main composer file for dev + check php-ffmpeg is instal…
Nov 29, 2024
37a138a
Update src/Symfony/Component/Validator/Constraints/VideoValidator.php
symfonyamlJan 7, 2025
6d607a1
Use named arguments as Nicolas Grekas suggested
symfonyamlJan 7, 2025
93c8747
Fix Psalm issue : Cannot find referenced variable $options in Video.php
Jan 7, 2025
980eeb8
CI Install ffmpeg in system dependencies for linux and windows tests
Jan 7, 2025
e9ebfa2
Video validator test requires extension fileinfo
Jan 9, 2025
9b48473
Fix coding standard from fabbot.io
Jan 9, 2025
ab74399
Remove group in CI + added phpdoc on video constraints
Jan 10, 2025
a083f66
VideoValidatorTest should be skipped if ffmpeg is not available on th…
Jan 10, 2025
cf56118
Applied coding standard suggested by fabbot.io
Jan 10, 2025
1b26cf2
Replace ctype_digit check with just a lower than comparison
Jan 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
[Validator] Add the Video constraint for validating video files
  • Loading branch information
symfonyaml committedJan 12, 2025
commitf6b91689a3ed5685dabaaf266a7b0bb4b40bf225
194 changes: 194 additions & 0 deletionssrc/Symfony/Component/Validator/Constraints/Video.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Validator\Constraints;

use Symfony\Component\Validator\Constraints\File;

/**
* @author Kev <https://github.com/symfonyaml>
*/
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class Video extends File
{
public const SIZE_NOT_DETECTED_ERROR = '6d55c3f4-e58e-4fe3-91ee-74b492199956';
public const TOO_WIDE_ERROR = '7f87163d-878f-47f5-99ba-a8eb723a1ab2';
public const TOO_NARROW_ERROR = '9afbd561-4f90-4a27-be62-1780fc43604a';
public const TOO_HIGH_ERROR = '7efae81c-4877-47ba-aa65-d01ccb0d4645';
public const TOO_LOW_ERROR = 'aef0cb6a-c07f-4894-bc08-1781420d7b4c';
public const TOO_FEW_PIXEL_ERROR = '1b06b97d-ae48-474e-978f-038a74854c43';
public const TOO_MANY_PIXEL_ERROR = 'ee0804e8-44db-4eac-9775-be91aaf72ce1';
public const RATIO_TOO_BIG_ERROR = '70cafca6-168f-41c9-8c8c-4e47a52be643';
public const RATIO_TOO_SMALL_ERROR = '59b8c6ef-bcf2-4ceb-afff-4642ed92f12e';
public const SQUARE_NOT_ALLOWED_ERROR = '5d41425b-facb-47f7-a55a-de9fbe45cb46';
public const LANDSCAPE_NOT_ALLOWED_ERROR = '6f895685-7cf2-4d65-b3da-9029c5581d88';
public const PORTRAIT_NOT_ALLOWED_ERROR = '65608156-77da-4c79-a88c-02ef6d18c782';
public const CORRUPTED_VIDEO_ERROR = '5d4163f3-648f-4e39-87fd-cc5ea7aad2d1';

// Include the mapping from the base class

protected const ERROR_NAMES = [
self::NOT_FOUND_ERROR => 'NOT_FOUND_ERROR',
self::NOT_READABLE_ERROR => 'NOT_READABLE_ERROR',
self::EMPTY_ERROR => 'EMPTY_ERROR',
self::TOO_LARGE_ERROR => 'TOO_LARGE_ERROR',
self::INVALID_MIME_TYPE_ERROR => 'INVALID_MIME_TYPE_ERROR',
self::FILENAME_TOO_LONG => 'FILENAME_TOO_LONG',
self::SIZE_NOT_DETECTED_ERROR => 'SIZE_NOT_DETECTED_ERROR',
self::TOO_WIDE_ERROR => 'TOO_WIDE_ERROR',
self::TOO_NARROW_ERROR => 'TOO_NARROW_ERROR',
self::TOO_HIGH_ERROR => 'TOO_HIGH_ERROR',
self::TOO_LOW_ERROR => 'TOO_LOW_ERROR',
self::TOO_FEW_PIXEL_ERROR => 'TOO_FEW_PIXEL_ERROR',
self::TOO_MANY_PIXEL_ERROR => 'TOO_MANY_PIXEL_ERROR',
self::RATIO_TOO_BIG_ERROR => 'RATIO_TOO_BIG_ERROR',
self::RATIO_TOO_SMALL_ERROR => 'RATIO_TOO_SMALL_ERROR',
self::SQUARE_NOT_ALLOWED_ERROR => 'SQUARE_NOT_ALLOWED_ERROR',
self::LANDSCAPE_NOT_ALLOWED_ERROR => 'LANDSCAPE_NOT_ALLOWED_ERROR',
self::PORTRAIT_NOT_ALLOWED_ERROR => 'PORTRAIT_NOT_ALLOWED_ERROR',
self::CORRUPTED_VIDEO_ERROR => 'CORRUPTED_VIDEO_ERROR',
];

/**
* @deprecated since Symfony 6.1, use const ERROR_NAMES instead
*/
protected static $errorNames = self::ERROR_NAMES;

public array|string $mimeTypes = 'video/*';
public ?int $minWidth = null;
public ?int $maxWidth = null;
public ?int $maxHeight = null;
public ?int $minHeight = null;
public int|float|null $maxRatio = null;
public int|float|null $minRatio = null;
public int|float|null $minPixels = null;
public int|float|null $maxPixels = null;
public ?bool $allowSquare = true;
public ?bool $allowLandscape = true;
public ?bool $allowPortrait = true;

// The constant for a wrong MIME type is taken from the parent class.
public string $mimeTypesMessage = 'This file is not a valid video.';
public string $sizeNotDetectedMessage = 'The size of the video could not be detected.';
public string $maxWidthMessage = 'The video width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.';
public string $minWidthMessage = 'The video width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px.';
public string $maxHeightMessage = 'The video height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px.';
public string $minHeightMessage = 'The video height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px.';
public string $minPixelsMessage = 'The video has too few pixels ({{ pixels }} pixels). Minimum amount expected is {{ min_pixels }} pixels.';
public string $maxPixelsMessage = 'The video has too many pixels ({{ pixels }} pixels). Maximum amount expected is {{ max_pixels }} pixels.';
public string $maxRatioMessage = 'The video ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.';
public string $minRatioMessage = 'The video ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.';
public string $allowSquareMessage = 'The video is square ({{ width }}x{{ height }}px). Square videos are not allowed.';
public string $allowLandscapeMessage = 'The video is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented videos are not allowed.';
public string $allowPortraitMessage = 'The video is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented videos are not allowed.';
public string $corruptedMessage = 'The video file is corrupted.';

public function __construct(
?array $options = null,
int|string|null $maxSize = null,
?bool $binaryFormat = null,
array|string|null $mimeTypes = null,
?int $filenameMaxLength = null,
?int $minWidth = null,
?int $maxWidth = null,
?int $maxHeight = null,
?int $minHeight = null,
int|float|null $maxRatio = null,
int|float|null $minRatio = null,
int|float|null $minPixels = null,
int|float|null $maxPixels = null,
?bool $allowSquare = null,
?bool $allowLandscape = null,
?bool $allowPortrait = null,
?string $notFoundMessage = null,
?string $notReadableMessage = null,
?string $maxSizeMessage = null,
?string $mimeTypesMessage = null,
?string $disallowEmptyMessage = null,
?string $filenameTooLongMessage = null,
?string $uploadIniSizeErrorMessage = null,
?string $uploadFormSizeErrorMessage = null,
?string $uploadPartialErrorMessage = null,
?string $uploadNoFileErrorMessage = null,
?string $uploadNoTmpDirErrorMessage = null,
?string $uploadCantWriteErrorMessage = null,
?string $uploadExtensionErrorMessage = null,
?string $uploadErrorMessage = null,
?string $sizeNotDetectedMessage = null,
?string $maxWidthMessage = null,
?string $minWidthMessage = null,
?string $maxHeightMessage = null,
?string $minHeightMessage = null,
?string $minPixelsMessage = null,
?string $maxPixelsMessage = null,
?string $maxRatioMessage = null,
?string $minRatioMessage = null,
?string $allowSquareMessage = null,
?string $allowLandscapeMessage = null,
?string $allowPortraitMessage = null,
?string $corruptedMessage = null,
?array $groups = null,
mixed $payload = null
) {
parent::__construct(
$options,
$maxSize,
$binaryFormat,
$mimeTypes,
$filenameMaxLength,
$notFoundMessage,
$notReadableMessage,
$maxSizeMessage,
$mimeTypesMessage,
$disallowEmptyMessage,
$filenameTooLongMessage,
$uploadIniSizeErrorMessage,
$uploadFormSizeErrorMessage,
$uploadPartialErrorMessage,
$uploadNoFileErrorMessage,
$uploadNoTmpDirErrorMessage,
$uploadCantWriteErrorMessage,
$uploadExtensionErrorMessage,
$uploadErrorMessage,
$groups,
$payload
);

$this->minWidth = $minWidth ?? $this->minWidth;
$this->maxWidth = $maxWidth ?? $this->maxWidth;
$this->maxHeight = $maxHeight ?? $this->maxHeight;
$this->minHeight = $minHeight ?? $this->minHeight;
$this->maxRatio = $maxRatio ?? $this->maxRatio;
$this->minRatio = $minRatio ?? $this->minRatio;
$this->minPixels = $minPixels ?? $this->minPixels;
$this->maxPixels = $maxPixels ?? $this->maxPixels;
$this->allowSquare = $allowSquare ?? $this->allowSquare;
$this->allowLandscape = $allowLandscape ?? $this->allowLandscape;
$this->allowPortrait = $allowPortrait ?? $this->allowPortrait;
$this->sizeNotDetectedMessage = $sizeNotDetectedMessage ?? $this->sizeNotDetectedMessage;
$this->maxWidthMessage = $maxWidthMessage ?? $this->maxWidthMessage;
$this->minWidthMessage = $minWidthMessage ?? $this->minWidthMessage;
$this->maxHeightMessage = $maxHeightMessage ?? $this->maxHeightMessage;
$this->minHeightMessage = $minHeightMessage ?? $this->minHeightMessage;
$this->minPixelsMessage = $minPixelsMessage ?? $this->minPixelsMessage;
$this->maxPixelsMessage = $maxPixelsMessage ?? $this->maxPixelsMessage;
$this->maxRatioMessage = $maxRatioMessage ?? $this->maxRatioMessage;
$this->minRatioMessage = $minRatioMessage ?? $this->minRatioMessage;
$this->allowSquareMessage = $allowSquareMessage ?? $this->allowSquareMessage;
$this->allowLandscapeMessage = $allowLandscapeMessage ?? $this->allowLandscapeMessage;
$this->allowPortraitMessage = $allowPortraitMessage ?? $this->allowPortraitMessage;
$this->corruptedMessage = $corruptedMessage ?? $this->corruptedMessage;

if (!\in_array('video/*', (array) $this->mimeTypes, true) && !\array_key_exists('mimeTypesMessage', $options ?? []) && null === $mimeTypesMessage) {
$this->mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.';
}
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp