public static function _getRelationPaths ($endClass, $fork = array (), $paths = array (), $processed = array (), $depth = 0)
	{
		
		// Remove first \ from end class
		
		if ($endClass[0] == '\\')
		{
			$endClass	= substr ($endClass, 1);
		}
		
		// Make sure fork is an array
		
		if ($fork === FALSE)
		{
			$fork	= array ();
		}
		
		// Set variables
		
		$class			= get_called_class ();
		$processed[]	= strtolower ($class);
		$parent			= $paths;
		
		$depth++;
		
		// Find paths to the end class
		// Loop through attributes
		
		foreach (static::$attributes as $name => $attribute)
		{
			
			// No attribute relation or class for the relation
			
			if (!isset ($attribute['relation']) || !class_exists ($attribute['relation']) || 
				(isset ($fork[$class]) && $fork[$class] != $name))
			{
				continue;
			}
			
			// Attribute relation matches the end class so add to paths
			
			else if ($attribute['relation'] == $endClass)
			{
				$paths[$name]	= $depth;
				continue;
			}
			
			// The attribute relation has already been processed
			
			else if (in_array (strtolower ($attribute['relation']), $processed))
			{
				continue;
			}
			
			// Recursively look at relation attributes
			
			else
			{
				$subPaths	= $attribute['relation']::_getRelationPaths ($endClass, $fork, $parent, $processed, $depth);
				
				if ($subPaths)
				{
					$paths[$name]	= $subPaths;
				}
				
			}
			
		}
		
		return $paths;
		
	}
public static function _getRelationPaths ($endClass, $fork = array (), $paths = array (), $processed = array (), $depth = 0)
	{
		
		// Remove first \ from end class
		
		if ($endClass[0] == '\\')
		{
			$endClass	= substr ($endClass, 1);
		}
		
		// Make sure fork is an array
		
		if ($fork === FALSE)
		{
			$fork	= array ();
		}
		
		// Set variables
		
		$class			= get_called_class ();
		$processed[]	= strtolower ($class);
		$parent			= $paths;
		
		$depth++;
		
		// Find paths to the end class
		// Loop through attributes
		
		foreach (static::$attributes as $name => $attribute)
		{
			
			// No attribute relation or class for the relation
			
			if (!isset ($attribute['relation']) || !class_exists ($attribute['relation']) || 
				(isset ($fork[$class]) && $fork[$class] != $name))
			{
				continue;
			}
			
			// Attribute relation matches the end class so add to paths
			
			else if ($attribute['relation'] == $endClass)
			{
				$paths[$name]	= $depth;
				continue;
			}
			
			// The attribute relation has already been processed
			
			else if (in_array (strtolower ($attribute['relation']), $processed))
			{
				continue;
			}
			
			// Recursively look at relation attributes
			
			else
			{
				$subPaths	= $attribute['relation']::_getRelationPaths ($endClass, $fork, $parent, $processed, $depth);
				
				if ($subPaths)
				{
					$paths[$name]	= $subPaths;
				}
				
			}
			
		}
		
		return $paths;
		
	}
public static function _getRelationPaths ( $ endClass , $ fork = array ( ) , $ paths = array ( ) , $ processed = array ( ) , $ depth = 0 ) { // Remove first \ from end class if ( $ endClass [ 0 ] == '\\' ) { $ endClass = substr ( $ endClass , 1 ) ; } // Make sure fork is an array if ( $ fork === FALSE ) { $ fork = array ( ) ; } // Set variables $ class = get_called_class ( ) ; $ processed [ ] = strtolower ( $ class ) ; $ parent = $ paths ; $ depth ++ ; // Find paths to the end class // Loop through attributes foreach ( static :: $ attributes as $ name => $ attribute ) { // No attribute relation or class for the relation if ( ! isset ( $ attribute [ 'relation' ] ) || ! class_exists ( $ attribute [ 'relation' ] ) || ( isset ( $ fork [ $ class ] ) && $ fork [ $ class ] != $ name ) ) { continue ; } // Attribute relation matches the end class so add to paths else if ( $ attribute [ 'relation' ] == $ endClass ) { $ paths [ $ name ] = $ depth ; continue ; } // The attribute relation has already been processed else if ( in_array ( strtolower ( $ attribute [ 'relation' ] ) , $ processed ) ) { continue ; } // Recursively look at relation attributes else { $ subPaths = $ attribute [ 'relation' ] :: _getRelationPaths ( $ endClass , $ fork , $ parent , $ processed , $ depth ) ; if ( $ subPaths ) { $ paths [ $ name ] = $ subPaths ; } } } return $ paths ; }
Return an array of available paths to a related class
@param string $class Destination class
@param array $fork Used to determine which fork to use when there are
multiple attributes related to the same class (see getRelated comments)
@param array $paths Available paths, set recursively
@param array $processed Already processed classes, set recursively
@param integer $depth Path depth, set recursively
@return array
Return an array of available paths to a related class