File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Domain/Question/Validation Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1717use thofman \KnowledgeBase \Domain \Question \Tag ;
1818use thofman \KnowledgeBase \Domain \Question \Validation \AlwaysValidValidator ;
1919use thofman \KnowledgeBase \Domain \Question \Validation \NonEmptyStringValidator ;
20+ use thofman \KnowledgeBase \Domain \Question \Validation \UrlSchemeHttpsValidator ;
2021use thofman \KnowledgeBase \Domain \Question \Validation \UrlValidator ;
2122
2223#[AsCommand(name: 'app:add-article ' , description: 'Add an article ' )]
@@ -55,8 +56,10 @@ static function (string $value): string {
5556 throw new RuntimeException ($ validationResult ->validationErrorMessage );
5657 }
5758
58- if (parse_url ($ validationResult ->value , PHP_URL_SCHEME ) !== 'https ' ) {
59- throw new RuntimeException ('URL must be secure (https) ' );
59+ $ urlSchemeHttpsValidator = new UrlSchemeHttpsValidator ($ urlValidator );
60+ $ validationResult = $ urlSchemeHttpsValidator ->validate ($ value );
61+ if (!$ validationResult ->isValid ) {
62+ throw new RuntimeException ($ validationResult ->validationErrorMessage );
6063 }
6164
6265 return new StringSanitizer ()->sanitize ($ validationResult ->value );
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace thofman \KnowledgeBase \Domain \Question \Validation ;
5+
6+ final readonly class UrlSchemeHttpsValidator implements Validator
7+ {
8+ public function __construct (
9+ private UrlValidator $ urlValidator ,
10+ ) {
11+ }
12+
13+ public function validate (string $ value ): ValidationResult
14+ {
15+ $ validationResult = $ this ->urlValidator ->validate ($ value );
16+ if (!$ validationResult ->isValid ) {
17+ return $ validationResult ;
18+ }
19+
20+ if (parse_url ($ validationResult ->value , PHP_URL_SCHEME ) !== 'https ' ) {
21+ return ValidationResult::invalid ('URL must be secure (https) ' );
22+ }
23+
24+ return ValidationResult::valid ($ validationResult ->value );
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments