przewiń do treści

PHP, MySQL i MVC. Tworzenie witryn WWW opartych na bazie danych

Włodzimierz Gajda

class XMLArticle
{

    private $xml = '';
    public  $a;

    public function __construct($filename)
    {
        $this->load($filename);
        $this->unserialize();
    }

    public function load($filename)
    {
        $gzfile = gzopen($filename, 'r');
        if ($filename === false) {
            throw new Exception('XMLArticle::load() exception');
        }
        $this->xml = '';
        while (!gzeof($gzfile)) {
            $this->xml .= gzread($gzfile, 10000);
        }
        gzclose($gzfile);
    }

    public function unserialize()
    {
        $unserializer = new XML_Unserializer();

        $options = array(
            'forceEnum' => array('item'),
        );
        $unserializer->setOptions($options);

        $unserializer->unserialize($this->xml, false);
        $this->a = $unserializer->getUnserializedData();
    }

    public function getFiguresCount()
    {
        return $this->a['figures_count'];
    }

    public function getFigure($i)
    {
        return $this->a['figures']['item'][$i - 1];
    }

    public function getListingsCount()
    {
        return $this->a['listings_count'];
    }

    public function getListing($i)
    {
        return $this->a['listings']['item'][$i - 1];
    }
    
    ...

}

Listing 31.6. Zarys klasy XMLArticle

Rozdział 31. Skompresowane dokumenty XML zawierające dane binarne

listing-31-06.txt

Reklama

Szkolenia z Symfony 2.0