?
Current File : /home/c/i/d/cideo/www/wp-includesVIp/js/crop/images/Iterator.tar
Default.php000066600000004504151251732300006647 0ustar00<?php

/**
 * @category   Shanty
 * @package    Shanty_Mongo
 * @copyright  Shanty Tech Pty Ltd
 * @license    New BSD License
 * @author     Coen Hyde
 */
class Shanty_Mongo_Iterator_Default implements SeekableIterator, RecursiveIterator, Countable
{
	protected $_document = null;
	protected $_position = null;
	protected $_properties = array();
	protected $_init = false;
	protected $_counter = 0;
	
	public function __construct(Shanty_Mongo_Document $document)
	{
		$this->_document = $document;
		$this->_properties = $document->getPropertyKeys();
		$this->_position = current($this->_properties);
		
		reset($this->_properties);
	}
	
	/**
	 * Get the document
	 * 
	 * @return Shanty_Mongo_Document
	 */
	public function getDocument()
	{
		return $this->_document;
	}
	
	/**
	 * Get the properties
	 * 
	 * @return array
	 */
	public function getDocumentProperties()
	{
		return $this->_properties;
	}
	
	/**
	 * Seek to a position
	 * 
	 * @param unknown_type $position
	 */
	public function seek($position)
	{
		$this->_position = $position;
		
		if (!$this->valid()) {
			throw new OutOfBoundsException("invalid seek position ($position)");
		}
	}
	
	/**
	 * Get the current value
	 * 
	 * @return mixed
	 */
	public function current()
	{
		return $this->getDocument()->getProperty($this->key());
	}
	
	/**
	 * Get the current key
	 * 
	 * @return string
	 */
	public function key()
	{
		return $this->_position;
	}
	
	/**
	 * Move next
	 */
	public function next()
	{
		next($this->_properties);
		$this->_position = current($this->_properties);
		$this->_counter = $this->_counter + 1;
	}
	
	/**
	 * Rewind the iterator
	 */
	public function rewind()
	{
		reset($this->_properties);
		$this->_position = current($this->_properties);
	}
	
	/**
	 * Is the current position valid
	 * 
	 * @return boolean
	 */
	public function valid()
	{
		return in_array($this->key(), $this->_properties, true);
	}

	/**
	 * Count all properties
	 * 
	 * @return int
	 */
	public function count()
	{
		return count($this->getDocumentProperties());
	}
	
	/**
	 * Determine if the current node has an children
	 * 
	 * @return boolean
	 */
	public function hasChildren()
	{
		return ($this->current() instanceof Shanty_Mongo_Document);
	}
	
	/*
	 * Get children
	 * 
	 * @return RecursiveIterator
	 */
	public function getChildren()
	{
		return $this->current()->getIterator();
	}
}Cursor.php000066600000006125151251732300006541 0ustar00<?php

/**
 * @category   Shanty
 * @package    Shanty_Mongo
 * @copyright  Shanty Tech Pty Ltd
 * @license    New BSD License
 * @author     Coen Hyde
 */
class Shanty_Mongo_Iterator_Cursor implements OuterIterator
{
	protected $_cursor = null;
	protected $_config = array();
	
	public function __construct(MongoCursor $cursor, $config)
	{
		$this->_cursor = $cursor;
		$this->_config = $config;
	}
	
	/**
	 * Get the inter iterator
	 * 
	 * @return MongoCursor
	 */
	public function getInnerIterator()
	{
		return $this->_cursor;
	}
	
	/**
	 * Get the document class
	 * 
	 * @return string
	 */
	public function getDocumentClass()
	{
		return $this->_config['documentClass'];
	}
	
	/**
	 * Get the document set class
	 * 
	 * @return string
	 */
	public function getDocumentSetClass()
	{
		return $this->_config['documentSetClass'];
	}
	
	/**
	 * Export all data
	 * 
	 * @return array
	 */
	public function export()
	{
		$this->rewind();
		return iterator_to_array($this->getInnerIterator());
	}
	
	/**
	 * Construct a document set from this cursor
	 * 
	 * @return Shanty_Mongo_DocumentSet
	 */
	public function makeDocumentSet()
	{
		$config = array();
		$config['new'] = false;
		$config['hasId'] = false;
		$config['connectionGroup'] = $this->_config['connectionGroup'];
		$config['db'] = $this->_config['db'];
		$config['collection'] = $this->_config['collection'];
		$config['requirementModifiers'] = array(
			Shanty_Mongo_DocumentSet::DYNAMIC_INDEX => array("Document:".$this->getDocumentClass())
		);
		
		$documentSetClass = $this->getDocumentSetClass();
		return new $documentSetClass($this->export(), $config);
	}
	
	/**
	 * Get the current value
	 * 
	 * @return mixed
	 */
	public function current()
	{
		$data = $this->getInnerIterator()->current();
		if ($data === null) {
		    return null;
		}
		
		$config                    = array();
		$config['new']             = false;
		$config['hasKey']          = true;
		$config['connectionGroup'] = $this->_config['connectionGroup'];
		$config['db']              = $this->_config['db'];
		$config['collection']      = $this->_config['collection'];
		
		$documentClass = $this->getDocumentClass();
        if (!empty($data['_type'][0])) {
            $documentClass = $data['_type'][0];
        }
        
		return new $documentClass($data, $config);
	}
	
	public function getNext()
	{
		$this->next();
		return $this->current();
	}
	
	public function key()
	{
		return $this->getInnerIterator()->key();
	}
	
	public function next()
	{
		return $this->getInnerIterator()->next();
	}
	
	public function rewind()
	{
		return $this->getInnerIterator()->rewind();
	}
	
	public function valid()
	{
		return $this->getInnerIterator()->valid();
	}
	
	public function count($all = false)
	{
		return $this->getInnerIterator()->count($all);
	}
	
	public function info()
	{
		return $this->getInnerIterator()->info();
	}
	
	public function __call($method, $arguments)
	{
		// Forward the call to the MongoCursor
		$res = call_user_func_array(array($this->getInnerIterator(), $method), $arguments);
		
		// Allow chaining
		if ($res instanceof MongoCursor) {
			return $this;
		}
		
		return $res;
	}
}