2727use Spaze \SecurityTxt \Violations \SecurityTxtEncryptionNotUri ;
2828use Spaze \SecurityTxt \Violations \SecurityTxtExpired ;
2929use Spaze \SecurityTxt \Violations \SecurityTxtExpiresTooLong ;
30+ use Spaze \SecurityTxt \Violations \SecurityTxtFileLocationNotHttps ;
31+ use Spaze \SecurityTxt \Violations \SecurityTxtFileLocationNotUri ;
3032use Spaze \SecurityTxt \Violations \SecurityTxtHiringNotHttps ;
3133use Spaze \SecurityTxt \Violations \SecurityTxtHiringNotUri ;
3234use Spaze \SecurityTxt \Violations \SecurityTxtPolicyNotHttps ;
@@ -42,6 +44,7 @@ final class SecurityTxt implements JsonSerializable
4244 public const string CHARSET = 'charset=utf-8 ' ;
4345 public const string CONTENT_TYPE_HEADER = self ::CONTENT_TYPE . '; ' . self ::CHARSET ;
4446
47+ private ?string $ fileLocation = null ;
4548 private ?SecurityTxtExpires $ expires = null ;
4649 private ?SecurityTxtSignatureVerifyResult $ signatureVerifyResult = null ;
4750 private ?SecurityTxtPreferredLanguages $ preferredLanguages = null ;
@@ -88,13 +91,32 @@ public function __construct(
8891 }
8992
9093
94+ public function setFileLocation (string $ fileLocation ): void
95+ {
96+ $ this ->setValue (
97+ function () use ($ fileLocation ): void {
98+ $ this ->fileLocation = $ fileLocation ;
99+ },
100+ function () use ($ fileLocation ): void {
101+ $ this ->checkUri ($ fileLocation , SecurityTxtFileLocationNotUri::class, SecurityTxtFileLocationNotHttps::class);
102+ },
103+ );
104+ }
105+
106+
107+ public function getFileLocation (): ?string
108+ {
109+ return $ this ->fileLocation ;
110+ }
111+
112+
91113 /**
92114 * @throws SecurityTxtError
93115 * @throws SecurityTxtWarning
94116 */
95117 public function setExpires (SecurityTxtExpires $ expires ): void
96118 {
97- $ this ->setValue (
119+ $ this ->setFieldValue (
98120 function () use ($ expires ): SecurityTxtExpires {
99121 return $ this ->expires = $ expires ;
100122 },
@@ -137,7 +159,7 @@ public function getSignatureVerifyResult(): ?SecurityTxtSignatureVerifyResult
137159 */
138160 public function addCanonical (SecurityTxtCanonical $ canonical ): void
139161 {
140- $ this ->setValue (
162+ $ this ->setFieldValue (
141163 function () use ($ canonical ): SecurityTxtCanonical {
142164 return $ this ->canonical [] = $ canonical ;
143165 },
@@ -162,7 +184,7 @@ public function getCanonical(): array
162184 */
163185 public function addContact (SecurityTxtContact $ contact ): void
164186 {
165- $ this ->setValue (
187+ $ this ->setFieldValue (
166188 function () use ($ contact ): SecurityTxtContact {
167189 return $ this ->contact [] = $ contact ;
168190 },
@@ -187,7 +209,7 @@ public function getContact(): array
187209 */
188210 public function setPreferredLanguages (SecurityTxtPreferredLanguages $ preferredLanguages ): void
189211 {
190- $ this ->setValue (
212+ $ this ->setFieldValue (
191213 function () use ($ preferredLanguages ): SecurityTxtPreferredLanguages {
192214 return $ this ->preferredLanguages = $ preferredLanguages ;
193215 },
@@ -231,7 +253,7 @@ public function getPreferredLanguages(): ?SecurityTxtPreferredLanguages
231253 */
232254 public function addAcknowledgments (SecurityTxtAcknowledgments $ acknowledgments ): void
233255 {
234- $ this ->setValue (
256+ $ this ->setFieldValue (
235257 function () use ($ acknowledgments ): SecurityTxtAcknowledgments {
236258 return $ this ->acknowledgments [] = $ acknowledgments ;
237259 },
@@ -256,7 +278,7 @@ public function getAcknowledgments(): array
256278 */
257279 public function addHiring (SecurityTxtHiring $ hiring ): void
258280 {
259- $ this ->setValue (
281+ $ this ->setFieldValue (
260282 function () use ($ hiring ): SecurityTxtHiring {
261283 return $ this ->hiring [] = $ hiring ;
262284 },
@@ -281,7 +303,7 @@ public function getHiring(): array
281303 */
282304 public function addPolicy (SecurityTxtPolicy $ policy ): void
283305 {
284- $ this ->setValue (
306+ $ this ->setFieldValue (
285307 function () use ($ policy ): SecurityTxtPolicy {
286308 return $ this ->policy [] = $ policy ;
287309 },
@@ -306,7 +328,7 @@ public function getPolicy(): array
306328 */
307329 public function addEncryption (SecurityTxtEncryption $ encryption ): void
308330 {
309- $ this ->setValue (
331+ $ this ->setFieldValue (
310332 function () use ($ encryption ): SecurityTxtEncryption {
311333 return $ this ->encryption [] = $ encryption ;
312334 },
@@ -327,33 +349,49 @@ public function getEncryption(): array
327349
328350
329351 /**
330- * @param callable(): SecurityTxtFieldValue $setValue
352+ * @param callable(): void $setValue
331353 * @param callable(): void $validator
332- * @param (callable(): void)|null $warnings
333354 * @return void
334355 */
335- private function setValue (callable $ setValue , callable $ validator, ? callable $ warnings = null ): void
356+ private function setValue (callable $ setValue , callable $ validator ): void
336357 {
337358 if ($ this ->validationLevel === SecurityTxtValidationLevel::AllowInvalidValuesSilently) {
338- $ this -> orderedFields [] = $ setValue ();
359+ $ setValue ();
339360 return ;
340361 }
341362 if ($ this ->validationLevel === SecurityTxtValidationLevel::AllowInvalidValues) {
342- $ this -> orderedFields [] = $ setValue ();
363+ $ setValue ();
343364 $ validator ();
344365 } else {
345366 $ validator ();
346- $ this -> orderedFields [] = $ setValue ();
367+ $ setValue ();
347368 }
369+ }
370+
371+
372+ /**
373+ * @param callable(): SecurityTxtFieldValue $setValue
374+ * @param callable(): void $validator
375+ * @param (callable(): void)|null $warnings
376+ * @return void
377+ */
378+ private function setFieldValue (callable $ setValue , callable $ validator , ?callable $ warnings = null ): void
379+ {
380+ $ this ->setValue (
381+ function () use ($ setValue ): void {
382+ $ this ->orderedFields [] = $ setValue ();
383+ },
384+ $ validator ,
385+ );
348386 if ($ warnings !== null ) {
349387 $ warnings ();
350388 }
351389 }
352390
353391
354392 /**
355- * @param class-string<SecurityTxtAcknowledgmentsNotUri|SecurityTxtCanonicalNotUri|SecurityTxtContactNotUri|SecurityTxtEncryptionNotUri|SecurityTxtHiringNotUri|SecurityTxtPolicyNotUri> $notUriError
356- * @param class-string<SecurityTxtAcknowledgmentsNotHttps|SecurityTxtCanonicalNotHttps|SecurityTxtContactNotHttps|SecurityTxtEncryptionNotHttps|SecurityTxtHiringNotHttps|SecurityTxtPolicyNotHttps> $notHttpsError
393+ * @param class-string<SecurityTxtAcknowledgmentsNotUri|SecurityTxtCanonicalNotUri|SecurityTxtContactNotUri|SecurityTxtEncryptionNotUri|SecurityTxtHiringNotUri|SecurityTxtPolicyNotUri|SecurityTxtFileLocationNotUri > $notUriError
394+ * @param class-string<SecurityTxtAcknowledgmentsNotHttps|SecurityTxtCanonicalNotHttps|SecurityTxtContactNotHttps|SecurityTxtEncryptionNotHttps|SecurityTxtHiringNotHttps|SecurityTxtPolicyNotHttps|SecurityTxtFileLocationNotHttps > $notHttpsError
357395 * @throws SecurityTxtError
358396 */
359397 private function checkUri (string $ uri , string $ notUriError , string $ notHttpsError ): void
@@ -384,6 +422,7 @@ public function getOrderedFields(): array
384422 public function jsonSerialize (): array
385423 {
386424 return [
425+ 'fileLocation ' => $ this ->getFileLocation (),
387426 'expires ' => $ this ->getExpires (),
388427 'signatureVerifyResult ' => $ this ->getSignatureVerifyResult (),
389428 'preferredLanguages ' => $ this ->getPreferredLanguages (),
0 commit comments