Liturgical-Calendar / LiturgicalCalendarAPI

A PHP script / API endpoint that will generate the Roman Catholic liturgical calendar for any given year, calculating the mobile festivities and the precedence of solemnities, feasts, memorials...
Apache License 2.0
38 stars 10 forks source link

Calendar API Endpoint error when using National Preset #46

Closed ptrsmk closed 2 years ago

ptrsmk commented 2 years ago

Describe the bug When attempting to retrieve a calendar from the API using a national preset paramenter, an error is returned. Making the request without the national preset parameter does not return the error.

To Reproduce Enter in browser: https://johnromanodorazio.com/LiturgicalCalendar/LitCalEngine.php?year=2021&returntype=JSON&nationalpreset=USA Following Error is returned: Fatal error: Uncaught Error: Typed property Festivity::$liturgicalyear must not be accessed before initialization in /var/www/vhosts/johnromanodorazio.com/httpdocs/LiturgicalCalendar/Festivity.php:70 Stack trace: #0 [internal function]: Festivity->jsonSerialize() #1 /var/www/vhosts/johnromanodorazio.com/httpdocs/LiturgicalCalendar/LitCalEngine.php(2984): json_encode() #2 /var/www/vhosts/johnromanodorazio.com/httpdocs/LiturgicalCalendar/LitCalEngine.php(2951): GenerateResponseToRequest() #3 {main} thrown in /var/www/vhosts/johnromanodorazio.com/httpdocs/LiturgicalCalendar/Festivity.php on line 70

Expected behavior JSON calendar should be returned.

Screenshots image

Desktop (please complete the following information):

ptrsmk commented 2 years ago

This appears to be the issue: https://github.com/JohnRDOrazio/LiturgicalCalendar/blob/48ca5f8e0e928ebb2ccd61a2ae8b294d7aee4586/Festivity.php#L18

See: https://stackoverflow.com/a/59265626/378052

JohnRDOrazio commented 2 years ago

Thanks for letting me know! I've been updating the code with type declarations for better readability, and for a better experience in Code editors. Will fix soon, I'm busy rewriting the whole script from scratch, in OOP style, turning the engine into a class with methods.

JohnRDOrazio commented 2 years ago

I believe I have succeeded in rewriting the code as a class. This should make it easier to navigate the code even from within the Github interface. The development branch is now live at https://johnromanodorazio.com/LiturgicalCalendar-staging/ . Could you perhaps take a look and see if all seems well?

JohnRDOrazio commented 2 years ago

I have merged the recent activity from the development branch to the main branch, so this error no longer occurs. I am currently doing even more work to separate completely the API from the Frontend. I have also created an organization https://github.com/Liturgical-Calendar/ which will make it easier to keep any and all repositories having to do with the Liturgy or the Liturgical Calendar together, forming a kind of an ecosystem. I foresee a number of projects that can be built around the Liturgical Calendar API!

JohnRDOrazio commented 2 years ago

fixed in PR #47