本文整理汇总了PHP中Doctrine_Core::_loadedModelFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Core::_loadedModelFiles方法的具体用法?PHP Doctrine_Core::_loadedModelFiles怎么用?PHP Doctrine_Core::_loadedModelFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Core
的用法示例。
在下文中一共展示了Doctrine_Core::_loadedModelFiles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadModels
/**
* Recursively load all models from a directory or array of directories
*
* @param string $directory Path to directory of models or array of directory paths
* @param integer $modelLoading Pass value of Doctrine_Core::ATTR_MODEL_LOADING to force a certain style of model loading
* Allowed Doctrine_Core::MODEL_LOADING_AGGRESSIVE(default) or Doctrine_Core::MODEL_LOADING_CONSERVATIVE
* @param string $classPrefix The class prefix of the models to load. This is useful if the class name and file name are not the same
*/
public static function loadModels($directory, $modelLoading = null, $classPrefix = null)
{
self::$_loadedModelFiles = array();
$manager = Doctrine_Manager::getInstance();
$modelLoading = $modelLoading === null ? $manager->getAttribute(Doctrine_Core::ATTR_MODEL_LOADING) : $modelLoading;
$classPrefix = $classPrefix === null ? $manager->getAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX) : $classPrefix;
$loadedModels = array();
if ($directory !== null) {
foreach ((array) $directory as $dir) {
$dir = rtrim($dir, '/');
if (!is_dir($dir)) {
throw new Doctrine_Exception('You must pass a valid path to a directory containing Doctrine models');
}
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($it as $file) {
$e = explode('.', $file->getFileName());
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
if ($modelLoading == Doctrine_Core::MODEL_LOADING_PEAR) {
$className = str_replace($dir . DIRECTORY_SEPARATOR, null, $file->getPathName());
$className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
$className = substr($className, 0, strpos($className, '.'));
} else {
$className = $e[0];
}
if ($classPrefix) {
$className = $classPrefix . $className;
}
if (!class_exists($className, false)) {
if ($modelLoading == Doctrine_Core::MODEL_LOADING_CONSERVATIVE || $modelLoading == Doctrine_Core::MODEL_LOADING_PEAR) {
self::loadModel($className, $file->getPathName());
$loadedModels[$className] = $className;
} else {
$declaredBefore = get_declared_classes();
require_once $file->getPathName();
$declaredAfter = get_declared_classes();
// Using array_slice because array_diff is broken is some PHP versions
$foundClasses = array_slice($declaredAfter, count($declaredBefore));
if ($foundClasses) {
foreach ($foundClasses as $className) {
if (self::isValidModelClass($className)) {
$loadedModels[$className] = $className;
self::loadModel($className, $file->getPathName());
}
}
}
$previouslyLoaded = array_keys(self::$_loadedModelFiles, $file->getPathName());
if (!empty($previouslyLoaded)) {
$previouslyLoaded = array_combine(array_values($previouslyLoaded), array_values($previouslyLoaded));
$loadedModels = array_merge($loadedModels, $previouslyLoaded);
}
}
} else {
if (self::isValidModelClass($className)) {
$loadedModels[$className] = $className;
}
}
}
}
}
}
asort($loadedModels);
return $loadedModels;
}