public static function translate($term, &$config = array(), $depth = 0) { $zendAutoloader = Zend_Loader_Autoloader::getInstance(); $currentZendAutoloaderSetting = $zendAutoloader->suppressNotFoundWarnings(); $zendAutoloader->suppressNotFoundWarnings(TRUE); if ($depth > self::MAX_DEREF_DEPTH) { throw new Exepction('Model Reflection error: translated too deeply.'); } $myMute = Saf_Debug::mute(); if (!array_key_exists('_lateBindingParams', $config)) { $config['_lateBindingParams'] = array(); } $model = array(); $modelIsIterable = FALSE; $allowsNonString = array_key_exists('allowNonStrings', $config) && $config['allowNonStrings']; $termIsIterable = !array_key_exists('termIterable', $config) || $config['termIterable']; $term = trim($term); if (strpos($term, '*') === 0) { $term = substr($term, 1); //#TODO #2.0.0 if not unique, pull from cache } if ($termIsIterable && strpos($term, ';') !== FALSE) { $terms = explode(';', $term); } else { $terms = array($term); } try { foreach ($terms as $currentTerm) { $conditional = FALSE; if (strpos($currentTerm, '?') === 0) { $conditional = TRUE; $currentTerm = trim(substr($currentTerm, 1)); } $currentTerm = trim(self::_translateVariables($currentTerm, $conditional, $config)); if (strpos($currentTerm, '=') !== FALSE) { $tagParts = explode('=', $currentTerm, 2); $model[] = self::_translateTag(trim($tagParts[0]), trim($tagParts[1]), $conditional, $config, $depth + 1); } else { if (self::_validClassName($currentTerm)) { //#TODO #2.0.0 branch this out so it is framework agnostic $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->suppressNotFoundWarnings(TRUE); try { if (Zend_Loader_Autoloader::autoload($currentTerm)) { $modelObject = new $currentTerm(); $model[] = $modelObject; } else { //#TODO #1.1.0 $model[] = $currentTerm; } } catch (Exception $e) { $model[] = $currentTerm; } $autoloader->suppressNotFoundWarnings(FALSE); } else { $nextComment = strpos($currentTerm, '<!--'); $nextObjectRef = strpos($currentTerm, '->'); while ($nextComment !== FALSE && $nextObjectRef !== FALSE && $nextComment < $nextObjectRef) { $nextComment = strpos($currentTerm, '<!--', $nextObjectRef + 1); $nextObjectRef = strpos($currentTerm, '->', $nextObjectRef + 1); } $nextClassRef = strpos($currentTerm, '::'); //#TODO #2.0.0 simplify this logic since it can only be the first in the stack. if ($nextObjectRef !== FALSE && ($nextClassRef === FALSE || $nextObjectRef < $nextClassRef)) { $termObject = substr($currentTerm, 0, strpos($currentTerm, '->')); $termRest = substr($currentTerm, strpos($currentTerm, '->') + 2); $model[] = self::_translateObject($termObject, $termRest, $conditional, $config, $depth + 1); } else { if ($nextClassRef !== FALSE) { $termClass = substr($currentTerm, 0, strpos($currentTerm, '::')); $termRest = substr($currentTerm, strpos($currentTerm, '::') + 2); $model[] = self::_translateClass($termClass, $termRest, $conditional, $config, $depth + 1); //call_user_func(array($termParts[0],$termParts[1])); } else { $model[] = $currentTerm; } } } } } } catch (Exception $e) { Saf_Debug::unmute($myMute); throw $e; } Saf_Debug::unmute($myMute); $zendAutoloader->suppressNotFoundWarnings($currentZendAutoloaderSetting); return $allowsNonString ? $modelIsIterable ? $model : $model[0] : implode('', $model); }