當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ClassLoader::setPsr4方法代碼示例

本文整理匯總了PHP中Composer\Autoload\ClassLoader::setPsr4方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassLoader::setPsr4方法的具體用法?PHP ClassLoader::setPsr4怎麽用?PHP ClassLoader::setPsr4使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Composer\Autoload\ClassLoader的用法示例。


在下文中一共展示了ClassLoader::setPsr4方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: autoload

 /**
  * Autoloads all registered extension files with an instance of the app.
  *
  * @return void
  **/
 public function autoload($app)
 {
     $loader = new ClassLoader();
     $mapfile = $this->basefolder . '/vendor/composer/autoload_psr4.php';
     if (is_readable($mapfile)) {
         $map = (require $mapfile);
         foreach ($map as $namespace => $path) {
             $loader->setPsr4($namespace, $path);
         }
         $mapfile = $this->basefolder . '/vendor/composer/autoload_classmap.php';
         if (is_readable($mapfile)) {
             $map = (require $mapfile);
             $loader->addClassMap($map);
         }
         $loader->register();
     }
     $filepath = $this->basefolder . '/vendor/composer/autoload_files.php';
     if (is_readable($filepath)) {
         $files = (include $filepath);
         foreach ($files as $file) {
             try {
                 if (is_readable($file)) {
                     require $file;
                 }
             } catch (\Exception $e) {
                 $this->logInitFailure('Error importing extension class', $file, $e, Logger::ERROR);
             }
         }
     }
 }
開發者ID:ClemsB,項目名稱:bolt,代碼行數:35,代碼來源:Extensions.php

示例2: 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);
         }
     }
 }
開發者ID:jigoshop,項目名稱:Jigoshop2,代碼行數:21,代碼來源:Integration.php

示例3: 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;
    }
開發者ID:dazzle-libraries,項目名稱:composer,代碼行數:71,代碼來源:AutoloadGenerator.php

示例4: setPsr4

 /**
  * {@inheritdoc}
  */
 public function setPsr4($nsPrefix, $paths)
 {
     $this->autoloader->setPsr4($nsPrefix, $paths);
 }
開發者ID:IlyaGluschenko,項目名稱:test001,代碼行數:7,代碼來源:ClassLoaderWrapper.php

示例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');
 }
開發者ID:phpcq,項目名稱:autoload-validation,代碼行數:36,代碼來源:CheckAutoloading.php


注:本文中的Composer\Autoload\ClassLoader::setPsr4方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。