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