Completed
Branch master (f07b2a)
by Pierre-Henry
36:36
created

Link::__destruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 15.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @title            Link Class
4
 * @desc             Gets the Links in the XML file.
5
 *
6
 * @author           Pierre-Henry Soria <[email protected]>
7
 * @copyright        (c) 2012-2017, Pierre-Henry Soria. All Rights Reserved.
8
 * @license          GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
9
 * @package          PH7 / Framework / Xml
10
 * @version          1.0
11
 */
12
13
namespace PH7\Framework\Xml;
14
15
defined('PH7') or exit('Restricted access');
16
17
use DOMDocument;
18
19
class Link
20
{
21
    /** @var DOMDocument */
22
    private $_oXml;
23
24
    /** @var string */
25
    private $_sPath;
26
27
    /** @var array */
28
    private $_aRet = array();
29
30
    /**
31
     * Constructor with the instance of the DOMDocument object.
32
     *
33
     * @param string $sPath The path to the XML file. You can also specify an URL if the "allow_url_fopen" PHP directive is enabled.
34
     */
35
    public function __construct($sPath)
36
    {
37
        $this->_sPath = $sPath;
38
        $this->_oXml = new DOMDocument;
39
    }
40
41
    /**
42
     * Gets the XML links.
43
     *
44
     * @return array The XML tree.
45
     *
46
     * @throws Exception If the XML file is not found.
47
     */
48
    public function get()
49
    {
50
        if (!@$this->_oXml->load($this->_sPath)) {
51
            throw new Exception('The file \'' . $this->_sPath . '\' does not exist or is not a valid XML file.');
52
        }
53
54
        foreach ($this->_oXml->getElementsByTagName('link') as $oTag) {
55
            $this->_aRet[$oTag->getAttribute('url')] = $oTag->getAttribute('title');
56
        }
57
58
        return $this->_aRet;
59
    }
60
}
61