本文整理汇总了PHP中Composer\Autoload\ClassLoader::set方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader::set方法的具体用法?PHP ClassLoader::set怎么用?PHP ClassLoader::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Autoload\ClassLoader
的用法示例。
在下文中一共展示了ClassLoader::set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addComposerFiles
public static function addComposerFiles($dir)
{
if (file_exists($dir . '/vendor/composer/autoload_namespaces.php')) {
$map = (require $dir . '/vendor/composer/autoload_namespaces.php');
foreach ($map as $namespace => $path) {
self::$classLoader->set($namespace, $path);
}
}
if (file_exists($dir . '/vendor/composer/autoload_psr4.php')) {
$map = (require $dir . '/vendor/composer/autoload_psr4.php');
foreach ($map as $namespace => $path) {
self::$classLoader->setPsr4($namespace, $path);
}
}
if (file_exists($dir . '/vendor/composer/autoload_classmap.php')) {
$classMap = (require $dir . '/vendor/composer/autoload_classmap.php');
if ($classMap) {
self::$classLoader->addClassMap($classMap);
}
}
}
示例2: getStaticFile
protected function getStaticFile($suffix, $targetDir, $vendorPath, $basePath, &$staticPhpVersion)
{
$staticPhpVersion = 50600;
$file = <<<HEADER
<?php
// autoload_static.php @generated by Composer
namespace Composer\\Autoload;
class ComposerStaticInit{$suffix}
{
HEADER;
$loader = new ClassLoader();
$map = (require $targetDir . '/autoload_namespaces.php');
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = (require $targetDir . '/autoload_psr4.php');
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = (require $targetDir . '/autoload_classmap.php');
if ($classMap) {
$loader->addClassMap($classMap);
}
$filesystem = new Filesystem();
$vendorPathCode = ' ' . $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true, true) . " . '/";
$appBaseDirCode = ' ' . $filesystem->findShortestPathCode(realpath($targetDir), $basePath, true, true) . " . '/";
$absoluteVendorPathCode = ' ' . substr(var_export(rtrim($vendorDir, '\\/') . '/', true), 0, -1);
$absoluteAppBaseDirCode = ' ' . substr(var_export(rtrim($baseDir, '\\/') . '/', true), 0, -1);
$initializer = '';
$prefix = "Composer\\Autoload\\ClassLoader";
$prefixLen = strlen($prefix);
if (file_exists($targetDir . '/autoload_files.php')) {
$maps = array('files' => require $targetDir . '/autoload_files.php');
} else {
$maps = array();
}
foreach ((array) $loader as $prop => $value) {
if ($value && 0 === strpos($prop, $prefix)) {
$maps[substr($prop, $prefixLen)] = $value;
}
}
foreach ($maps as $prop => $value) {
if (count($value) > 32767) {
// Static arrays are limited to 32767 values on PHP 5.6
// See https://bugs.php.net/68057
$staticPhpVersion = 70000;
}
$value = var_export($value, true);
$value = str_replace($absoluteVendorPathCode, $vendorPathCode, $value);
$value = str_replace($absoluteAppBaseDirCode, $appBaseDirCode, $value);
$value = ltrim(preg_replace('/^ */m', ' $0$0', $value));
$file .= sprintf(" public static \$%s = %s;\n\n", $prop, $value);
if ('files' !== $prop) {
$initializer .= " \$loader->{$prop} = ComposerStaticInit{$suffix}::\${$prop};\n";
}
}
return $file . <<<INITIALIZER
public static function getInitializer(ClassLoader \$loader)
{
return \\Closure::bind(function () use (\$loader) {
{$initializer}
}, null, ClassLoader::class);
}
}
INITIALIZER;
}
示例3: setPsr0
/**
* {@inheritdoc}
*/
public function setPsr0($nsPrefix, $paths)
{
$this->autoloader->set($nsPrefix, $paths);
}
示例4: ClassLoader
<?php
use Composer\Autoload\ClassLoader;
use VCR\VCR;
require_once __DIR__ . '/../vendor/autoload.php';
$classloader = new ClassLoader();
$classloader->set('Wsdl2PhpGenerator', array('tests'));
$classloader->register();
VCR::configure()->setCassettePath('tests/fixtures/vcr');
VCR::turnOn();
示例5: prepareComposerFallbackLoader
/**
* Prepare the composer fallback loader.
*
* @param EnumeratingClassLoader $enumLoader The enum loader to add to.
*
* @param string $baseDir The base dir where the composer.json resides.
*
* @param array $composer The contents of the composer.json.
*
* @return void
*/
private function prepareComposerFallbackLoader(EnumeratingClassLoader $enumLoader, $baseDir, $composer)
{
$vendorDir = $baseDir . DIRECTORY_SEPARATOR . 'vendor';
if (isset($composer['extra']['vendor-dir'])) {
$vendorDir = $baseDir . DIRECTORY_SEPARATOR . $composer['extra']['vendor-dir'];
}
if (!is_dir($vendorDir)) {
return;
}
$loader = new ClassLoader();
if ($map = $this->includeIfExists($vendorDir . '/composer/autoload_namespaces.php')) {
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
}
if ($map = $this->includeIfExists($vendorDir . '/composer/autoload_psr4.php')) {
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
}
if ($classMap = $this->includeIfExists($vendorDir . '/composer/autoload_classmap.php')) {
$loader->addClassMap($classMap);
}
$enumLoader->add(array($loader, 'loadClass'), 'composer.fallback');
}