inigroups.inc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /** @file inigroups.inc
  3. * @ingroup Examples
  4. * @brief class IniGroups
  5. * @author Marcus Boerger
  6. * @date 2003 - 2005
  7. *
  8. * SPL - Standard PHP Library
  9. */
  10. if (!class_exists("KeyFilter", false)) require_once("keyfilter.inc");
  11. if (!class_exists("DbaReader", false)) require_once("dbareader.inc");
  12. /** @ingroup Examples
  13. * @brief Class to iterate all groups within an ini file.
  14. * @author Marcus Boerger
  15. * @version 1.1
  16. *
  17. * Using this class you can iterator over all groups of a ini file.
  18. *
  19. * This class uses a 'is-a' relation to KeyFilter in contrast to a 'has-a'
  20. * relation. Doing so both current() and key() methods must be overwritten.
  21. * If it would use a 'has-a' relation there would be much more to type...
  22. * but for puritists that would allow correctness in so far as then no
  23. * key() would be needed.
  24. */
  25. class IniGroups extends KeyFilter
  26. {
  27. /**
  28. * Construct an ini file group iterator from a filename.
  29. *
  30. * @param file Ini file to open.
  31. */
  32. function __construct($file) {
  33. parent::__construct(new DbaReader($file, 'inifile'), '^\[.*\]$');
  34. }
  35. /**
  36. * @return The current group.
  37. */
  38. function current() {
  39. return substr(parent::key(),1,-1);
  40. }
  41. /**
  42. * @return The current group.
  43. */
  44. function key() {
  45. return substr(parent::key(),1,-1);
  46. }
  47. }
  48. ?>