PEAR2_SimpleChannelFrontendPEAR2_SimpleChannelFrontend-0.2.0/php/PEAR2/Pyrus/PackageFile.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
 * \PEAR2\Pyrus\PackageFile
 *
 * PHP version 5
 *
 * @category  PEAR2
 * @package   PEAR2_Pyrus
 * @author    Greg Beaver <cellog@php.net>
 * @copyright 2010 The PEAR Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version   SVN: $Id$
 * @link      http://svn.php.net/viewvc/pear2/Pyrus/
 */

/**
 * Base class for a PEAR2 package file
 *
 * @category  PEAR2
 * @package   PEAR2_Pyrus
 * @author    Greg Beaver <cellog@php.net>
 * @copyright 2010 The PEAR Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link      http://svn.php.net/viewvc/pear2/Pyrus/
 */
namespace PEAR2\Pyrus;
class PackageFile implements PackageFileInterface
{
    public $info;
    public $path;
    function __construct($package, $class = 'PEAR2\Pyrus\PackageFile\v2', $isString = false)
    {
        if ($package instanceof PackageFileInterface) {
            $this->path = $package->getFilePath();
            return $this->info = $package;
        }

        $this->path = $package;
        $parser = new PackageFile\Parser\v2;
        if ($isString) {
            $data = $package;
        } else {
            $data = file_exists($package) ? file_get_contents($package) : false;
        }

        if ($data === false || empty($data)) {
            throw new PackageFile\Exception('Unable to open package xml file '
                . $package . ' or file was empty.');
        }

        $this->info = $parser->parse($data, $package, $class);
    }

    function __toString()
    {
        return $this->info->__toString();
    }

    function getValidator()
    {
        return $this->info->getValidator();
    }

    function getPackageFileObject()
    {
        return $this->info;
    }

    function __get($var)
    {
        return $this->info->__get($var);
    }

    function __set($var, $value)
    {
        return $this->info->__set($var, $value);
    }

    function __call($func, $args)
    {
        return call_user_func_array(array($this->info, $func), $args);
    }

    function toArray($forpackaging = false)
    {
        return $this->info->toArray($forpackaging);
    }
}
EOF