本文整理汇总了PHP中Autoloader::buildIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP Autoloader::buildIndex方法的具体用法?PHP Autoloader::buildIndex怎么用?PHP Autoloader::buildIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autoloader
的用法示例。
在下文中一共展示了Autoloader::buildIndex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFailBuildIndex
/**
* Building an index should fail if class definitions are not unique.
*
* @param Autoloader $autoloader An Autoloader which should fail
*
* @dataProvider provideTestFailBuildIndex
* @expectedException AutoloaderException_IndexBuildCollision
* @see Autoloader::buildIndex()
* @return void
*/
public function testFailBuildIndex(Autoloader $autoloader)
{
$autoloader->buildIndex();
}
示例2: Autoloader
}
$autoloader = new Autoloader(PATH_BASE);
$autoloader->register();
$autoloader->getIndex()->setIndexPath($autoloaderIndexFile);
$autoloader->getFileIterator()->setOnlyDirPattern("~/((core)|(depending)|(extensions))~");
$autoloader->getFileIterator()->setOnlyFilePattern("~\\.php\$~i");
$autoloader->getFileIterator()->addSkipDirPattern("~/((javascript)|(\\.settings)|(\\.todo)|(cache)|(log)|(temp))~");
$autoloader->getFileIterator()->addSkipFilePattern("~/\\.~");
if (apache_getenv("AUTOLOADER_BUILD_RUNNING")) {
die("System Initialisation is running. Please wait.");
}
if (!file_exists($autoloaderIndexFile)) {
displayStartupUserInfo();
try {
apache_setenv("AUTOLOADER_BUILD_RUNNING", true);
$autoloader->buildIndex();
apache_setenv("AUTOLOADER_BUILD_RUNNING", false);
} catch (AutoloaderException $e) {
if ($e instanceof AutoloaderException_Parser_IO) {
die("ERROR: Check you file permissions!");
} else {
if ($e instanceof AutoloaderException_IndexBuildCollision) {
if (!isAjaxRequest()) {
echo $e->getMessage();
}
} else {
var_dump($e);
die;
}
}
}
示例3: build
/**
* Build and deploy the index
*
* @return void
* @throws AutoloaderException_Builder_NoClassPath
* @throws AutoloaderException_Builder_NoDeployPath
* @throws AutoloaderException_Builder_IO
*/
public function build()
{
if (empty($this->_deployPath)) {
throw new AutoloaderException_Builder_NoDeployPath($this->_locale->sprintf("NO_DEPLOY_PATH"));
}
if (empty($this->_classPaths)) {
throw new AutoloaderException_Builder_NoClassPath($this->_locale->sprintf("NO_CLASS_PATH"));
}
$indexDirectory = $this->_deployPath . DIRECTORY_SEPARATOR . "index";
// Create directories
$this->_mkdir($this->_deployPath);
$this->_mkdir($indexDirectory);
// Build indexes
foreach ($this->_classPaths as $i => $classPath) {
$autoloader = new Autoloader($classPath);
// Setup the deployed index
$indexFile = "{$i}.php";
$index = new AutoloaderIndex_PHPArrayCode();
$index->setIndexPath($indexDirectory . DIRECTORY_SEPARATOR . $indexFile);
$index->addFilter(new AutoloaderIndexFilter_RelativePath($this->_deployPath));
// Don't index our own classes
$autoloader->getFileIterator()->addSkipPattern("/InstantAutoloader\\.php\$/");
// Build index
$autoloader->setIndex($index);
$autoloader->buildIndex();
}
// Copy InstantAutoloader
$isCopied = copy(__DIR__ . DIRECTORY_SEPARATOR . "InstantAutoloader.php", $this->_deployPath . DIRECTORY_SEPARATOR . "InstantAutoloader.php");
if (!$isCopied) {
throw new AutoloaderException_Builder_IO($this->_locale->sprintf("FAILED_COPY_INSTANTAUTOLOADER"));
}
// Code for autoloading
$autoloadMethod = $this->_classLoaderMode == self::MODE_AUTOLOAD ? "register" : "requireAll";
$code = "<?php\n\n" . "/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */\n\n" . "/**\n" . " * Autoloader\n" . " * \n" . " * This code was generated automatically.\n" . " * Don't edit this file. Changes will get lost when\n" . " * building a new autoloader.\n" . " *\n" . " * @see AutoloaderBuilder::build()\n" . " * @link http://php-autoloader.malkusch.de/en/\n" . " */\n\n" . "namespace " . __NAMESPACE__ . ";\n\n" . "require_once __DIR__ . '/InstantAutoloader.php';\n";
foreach ($this->_classPaths as $i => $classPath) {
$indexPath = "__DIR__ . '/index/{$i}.php'";
$code .= "\n\$_autoloader = new InstantAutoloader({$indexPath});\n" . "\$_autoloader->setBasePath(__DIR__);\n" . "\$_autoloader->{$autoloadMethod}();\n";
}
$code .= "unset(\$_autoloader);";
$isPut = @\file_put_contents($this->getAutoloaderFile(), $code);
if (!$isPut) {
$error = \error_get_last();
throw new AutoloaderException_Builder_IO($this->_locale->sprintf("FAILED_GENERATING_CODE", $error["message"]));
}
\chmod($this->getAutoloaderFile(), 0644);
}