Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • no validation is made, that it's a valid XML (e.g. placing "&" instead of "&" won't break anything
  • the XML is treated like a regular string and therefore typical XML errors (e.g. pair tag name mismatch) are simply ignored
  • when unknown XML settings are added developer isn't informed about that, which can lead to code working in unexpected ways

Solution

The plan below would allow separate all template comment related logic into one class and allow addition of new settings later if needed.

  1. create the "TemplateCommentParser" class, that:
    1. would accept path to template as constructor argument
    2. the "parse" method would return associative array of results
  2. add support for data types in the class:
    1. "string" - any string
    2. "boolean" - true (when "yes"), false (when "no"), exception otherwise
    3. "integer" - as-as, when a positive integer, exception otherwise
    4. "category_path" - would split value by "||" and trim each each element
  3. define supported settings and their data types as class properties
  4. when template doesn't exist throw an exception
  5. when no meta comment found, then return an empty array
  6. when meta comment found:
    1. if it's one line long, then return an empty array
    2. if it's invalid XML, then throw an exception
    3. when unsupported setting found, then throw an exception
    4. when supported setting found, but it has value unknown format, then throw an exception
  7. return parsing result

Related Discussions

Related Tasks