u01jmg3 / ics-parser

Parser for iCalendar Events • PHP 8+, 7 (≥ 7.4), 5 (≥ 5.6)
MIT License
448 stars 144 forks source link

How to know that parsed url is valid iCAL? #288

Closed antonioperic closed 4 months ago

antonioperic commented 2 years ago

Hi,

don't know where to ask, so I will try here.

I am using this line of code

$iCal = new ICal($message->getCalendarUrl());

and the result is always a valid object. Even if I send 'something' as calendarUrl

example of result

ICal\ICal {#3324
  +alarmCount: 0
  +eventCount: 0
  +freeBusyCount: 0
  +todoCount: 0
  +defaultSpan: 2
  +defaultTimeZone: "UTC"
  +defaultWeekStart: "MO"
  +skipRecurrence: false
  +disableCharacterReplacement: false
  +filterDaysBefore: null
  +filterDaysAfter: null
  +cal: []
  #freeBusyIndex: 0
  #lastKeyword: null
  #validIanaTimeZones: []
  #alteredRecurrenceInstances: []
  #weekdays: array:7 [
    "MO" => "monday"
    "TU" => "tuesday"
    "WE" => "wednesday"
    "TH" => "thursday"
    "FR" => "friday"
    "SA" => "saturday"
    "SU" => "sunday"
  ]
  #frequencyConversion: array:4 [
    "DAILY" => "day"
    "WEEKLY" => "week"
    "MONTHLY" => "month"
    "YEARLY" => "year"
  ]
  #httpBasicAuth: []
  #httpUserAgent: null
  #httpAcceptLanguage: null
  -windowMinTimestamp: -2147483648
  -windowMaxTimestamp: 9223372036854775807
  -shouldFilterByWindow: false
}

How I can know that parsed URL, or text is a valid calendar file?

thank you

u01jmg3 commented 2 years ago

Great question - there currently isn't a mechanism for this functionality.

What would you expect? A new property called isValid which returns true or false?

nunodonato commented 2 years ago

Great question - there currently isn't a mechanism for this functionality.

What would you expect? A new property called isValid which returns true or false?

I just bumped into this problem today as well :) I was wondering why it was working with garbage input, I just assumed it would return NULL if no calendar was found.

u01jmg3 commented 4 months ago

Please feel free to reopen if/when you'd like to submit a PR.