Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-downloadable
Model
Sample
ContentValidator.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Downloadable\Model\Sample
;
7
8
use
Magento\Downloadable\Api\Data\SampleInterface
;
9
use
Magento\Downloadable\Model\File\ContentValidator
as FileContentValidator;
10
use
Magento\Framework\Exception\InputException
;
11
use
Magento\Framework\Url\Validator
as UrlValidator;
12
13
class
ContentValidator
14
{
18
protected
$urlValidator
;
19
23
protected
$fileContentValidator
;
24
29
public
function
__construct
(
30
FileContentValidator
$fileContentValidator
,
31
UrlValidator
$urlValidator
32
) {
33
$this->fileContentValidator =
$fileContentValidator
;
34
$this->urlValidator =
$urlValidator
;
35
}
36
45
public
function
isValid
(
SampleInterface
$sample, $validateSampleContent =
true
)
46
{
47
if
(filter_var($sample->
getSortOrder
(), FILTER_VALIDATE_INT) ===
false
|| $sample->
getSortOrder
() < 0) {
48
throw
new
InputException
(
__
(
'Sort order must be a positive integer.'
));
49
}
50
51
if
($validateSampleContent) {
52
$this->
validateSampleResource
($sample);
53
}
54
return
true
;
55
}
56
64
protected
function
validateSampleResource
(
SampleInterface
$sample)
65
{
66
$sampleFile = $sample->
getSampleFileContent
();
67
if
($sample->
getSampleType
() ==
'file'
68
&& (!$sampleFile || !$this->fileContentValidator->isValid($sampleFile))
69
) {
70
throw
new
InputException
(
__
(
'Provided file content must be valid base64 encoded data.'
));
71
}
72
73
if
($sample->
getSampleType
() ==
'url'
74
&& !$this->urlValidator->isValid($sample->
getSampleUrl
())
75
) {
76
throw
new
InputException
(
__
(
'Sample URL must have valid format.'
));
77
}
78
}
79
}
Magento\Framework\Url\Validator
Definition:
Validator.php:14
Magento\Downloadable\Model\Sample\ContentValidator\validateSampleResource
validateSampleResource(SampleInterface $sample)
Definition:
ContentValidator.php:64
Magento\Downloadable\Model\File\ContentValidator
Definition:
ContentValidator.php:11
Magento\Downloadable\Model\Sample
Definition:
Builder.php:6
__
__()
Definition:
__.php:13
Magento\Framework\Exception\InputException
Definition:
InputException.php:17
Magento\Downloadable\Api\Data\SampleInterface\getSampleUrl
getSampleUrl()
Magento\Downloadable\Api\Data\SampleInterface\getSampleType
getSampleType()
Magento\Downloadable\Model\Sample\ContentValidator\$urlValidator
$urlValidator
Definition:
ContentValidator.php:18
Magento\Downloadable\Model\Sample\ContentValidator\$fileContentValidator
$fileContentValidator
Definition:
ContentValidator.php:23
Magento\Downloadable\Model\Sample\ContentValidator
Definition:
ContentValidator.php:13
Magento\Downloadable\Model\Sample\ContentValidator\__construct
__construct(FileContentValidator $fileContentValidator, UrlValidator $urlValidator)
Definition:
ContentValidator.php:29
Magento\Downloadable\Api\Data\SampleInterface
Definition:
SampleInterface.php:15
Magento\Downloadable\Model\Sample\ContentValidator\isValid
isValid(SampleInterface $sample, $validateSampleContent=true)
Definition:
ContentValidator.php:45
Magento\Downloadable\Api\Data\SampleInterface\getSampleFileContent
getSampleFileContent()
Magento\Downloadable\Api\Data\SampleInterface\getSortOrder
getSortOrder()