<?php
/**
 * @author Alan Dix
 *
 * Version 0.9
 * Copyright (c) 2012
 *
 * see http://www.alandix.com/code/public-suffix/
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
 
require_once 'manage_sld.class.php';

if ( ! 
defined('PUBLIC_SUFFIX_PREFIX') ) define('PUBLIC_SUFFIX_PREFIX','public_suffix_');

define'PS_META_COLL'PUBLIC_SUFFIX_PREFIX 'meta' );
define'PS_RULES_COLL'PUBLIC_SUFFIX_PREFIX 'rules' );

class 
NosqliteRuleStoreSLD extends RuleStoreSLD {
    var 
$nosqlite$emta$rules;
    
//     var $tld_index = array();   // inherited from RuleStoreSLD

    
function __construct($nosqlite) {
        
$this->nosqlite $nosqlite;
        
$this->meta $nosqlite->selectCollection(PS_META_COLL);
        
$this->rules $nosqlite->selectCollection(PS_RULES_COLL);
    }
    
    function 
save($manageSLD=false) {  // optional argument if you want to store meta data for caching
        
$timestamp time();
        foreach( 
$this->tld_index as $tld => $rules ) {
            
$this->rules->put$tld, array( 'rules'=>$rules ) );
        }
        
$meta = array( 'timestamp'=>$timestamp );
        if ( 
$manageSLD ) {
            
$meta['line_ct'] = $manageSLD->line_ct;
            
$meta['rule_ct'] = $manageSLD->rule_ct;
            
$meta['read_time'] = $manageSLD->read_time;
            
$meta['parse_time'] = $manageSLD->parse_time;
        }
        
$this->meta->put'meta'$meta );
    }
    
    function 
getMeta() {
        return 
$this->meta->get'meta' );
    }
    
    function 
getRules$tld ) {
        if ( ! 
array_key_exists$tld$this->tld_index ) ) {
            
$tld_info $this->rules->get$tld );
            if ( ! 
$tld_info || ! $tld_info['rules'] ) {
                
$this->tld_index[$tld] = array();
            } else {
                
$this->tld_index[$tld] = $tld_info['rules'];
            }
        }
        return 
$this->tld_index[$tld];
    }
    
}


?>