当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassLoader::registerPath方法代码示例

本文整理汇总了PHP中lang\ClassLoader::registerPath方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader::registerPath方法的具体用法?PHP ClassLoader::registerPath怎么用?PHP ClassLoader::registerPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lang\ClassLoader的用法示例。


在下文中一共展示了ClassLoader::registerPath方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: entry

function entry(&$argv)
{
    if (is_file($argv[0])) {
        if (0 === substr_compare($argv[0], '.class.php', -10)) {
            $uri = realpath($argv[0]);
            if (null === ($cl = \lang\ClassLoader::getDefault()->findUri($uri))) {
                throw new \Exception('Cannot load ' . $uri . ' - not in class path');
            }
            return $cl->loadUri($uri)->literal();
        } else {
            if (0 === substr_compare($argv[0], '.xar', -4)) {
                $cl = \lang\ClassLoader::registerPath($argv[0]);
                if (!$cl->providesResource('META-INF/manifest.ini')) {
                    throw new \Exception($cl->toString() . ' does not provide a manifest');
                }
                $manifest = parse_ini_string($cl->getResource('META-INF/manifest.ini'));
                return strtr($manifest['main-class'], '.', '\\');
            } else {
                array_unshift($argv, 'eval');
                return 'xp\\runtime\\Evaluate';
            }
        }
    } else {
        return strtr($argv[0], '.', '\\');
    }
}
开发者ID:xp-runners,项目名称:main,代码行数:26,代码来源:entry.php

示例2: main

 /**
  * Runner method
  *
  */
 public static function main(array $args)
 {
     // Show command usage if invoked without arguments
     if (!$args) {
         exit(self::usage(\lang\XPClass::forName(\xp::nameOf(__CLASS__))));
     }
     $root = new RootDoc();
     for ($i = 0, $s = sizeof($args); $i < $s; $i++) {
         if ('-sp' === $args[$i]) {
             $root->setSourcePath(explode(PATH_SEPARATOR, $args[++$i]));
         } else {
             if ('-cp' === $args[$i]) {
                 foreach (explode(PATH_SEPARATOR, $args[++$i]) as $element) {
                     \lang\ClassLoader::registerPath($element);
                 }
             } else {
                 try {
                     $class = \lang\XPClass::forName($args[$i]);
                 } catch (\lang\ClassNotFoundException $e) {
                     \util\cmd\Console::$err->writeLine('*** ', $e->getMessage());
                     exit(2);
                 }
                 if (!$class->isSubclassOf('text.doclet.Doclet')) {
                     \util\cmd\Console::$err->writeLine('*** ', $class, ' is not a doclet');
                     exit(2);
                 }
                 $doclet = $class->newInstance();
                 $params = new ParamString(array_slice($args, $i));
                 // Show doclet usage if the command line contains "-?" (at any point).
                 if ($params->exists('help', '?')) {
                     self::usage($class);
                     if ($valid = $doclet->validOptions()) {
                         \util\cmd\Console::$err->writeLine();
                         \util\cmd\Console::$err->writeLine('Options:');
                         foreach ($valid as $name => $value) {
                             \util\cmd\Console::$err->writeLine('  * --', $name, OPTION_ONLY == $value ? '' : '=<value>');
                         }
                     }
                     exit(3);
                 }
                 $root->start($doclet, $params);
                 exit(0);
             }
         }
     }
     \util\cmd\Console::$err->writeLine('*** No doclet classname given');
     exit(1);
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:52,代码来源:Runner.class.php

示例3: foreach

<?php

namespace xp;

foreach ($bootstrap['files'] as $file) {
    require $file;
}
if (class_exists('xp', false)) {
    foreach ($bootstrap['overlay'] as $path) {
        \lang\ClassLoader::registerPath($path, true);
    }
    foreach ($bootstrap['local'] as $path) {
        \lang\ClassLoader::registerPath($path);
    }
} else {
    if (isset($bootstrap['base'])) {
        $paths = array_merge($bootstrap['overlay'], $bootstrap['core'], $bootstrap['local']);
        require $bootstrap['base'];
    } else {
        $parts = explode(PATH_SEPARATOR . PATH_SEPARATOR, get_include_path());
        throw new \Exception(sprintf("Cannot locate xp-framework/core anywhere in {\n  modules:   %s\n  classpath: %s\n}", ($p = rtrim($parts[0], PATH_SEPARATOR)) ? "[{$p}]" : '(empty)', ($p = rtrim($parts[1], PATH_SEPARATOR)) ? "[{$p}]" : '(empty)'), -1);
    }
}
开发者ID:xp-runners,项目名称:main,代码行数:23,代码来源:class-path.php

示例4: run

 /**
  * Main method
  *
  * @param   util.cmd.ParamString params
  * @return  int
  */
 public function run(ParamString $params)
 {
     // No arguments given - show our own usage
     if ($params->count < 1) {
         return self::usage();
     }
     // Configure properties
     $pm = PropertyManager::getInstance();
     // Separate runner options from class options
     for ($offset = 0, $i = 0; $i < $params->count; $i++) {
         switch ($params->list[$i]) {
             case '-c':
                 if (0 == strncmp('res://', $params->list[$i + 1], 6)) {
                     $pm->appendSource(new ResourcePropertySource(substr($params->list[$i + 1], 6)));
                 } else {
                     $pm->appendSource(new FilesystemPropertySource($params->list[$i + 1]));
                 }
                 $offset += 2;
                 $i++;
                 break;
             case '-cp':
                 \lang\ClassLoader::registerPath($params->list[$i + 1], null);
                 $offset += 2;
                 $i++;
                 break;
             case '-v':
                 $this->verbose = true;
                 $offset += 1;
                 $i++;
                 break;
             case '-?':
                 return self::usage();
             default:
                 break 2;
         }
     }
     // Sanity check
     if (!$params->exists($offset)) {
         self::$err->writeLine('*** Missing classname');
         return 1;
     }
     // Use default path for PropertyManager if no sources set
     if (!$pm->getSources()) {
         $pm->configure(self::DEFAULT_CONFIG_PATH);
     }
     unset($params->list[-1]);
     $classname = $params->value($offset);
     $classparams = new ParamString(array_slice($params->list, $offset + 1));
     // Class file or class name
     if (strstr($classname, \xp::CLASS_FILE_EXT)) {
         $file = new \io\File($classname);
         if (!$file->exists()) {
             self::$err->writeLine('*** Cannot load class from non-existant file ', $classname);
             return 1;
         }
         try {
             $class = \lang\ClassLoader::getDefault()->loadUri($file->getURI());
         } catch (\lang\ClassNotFoundException $e) {
             self::$err->writeLine('*** ', $this->verbose ? $e : $e->getMessage());
             return 1;
         }
     } else {
         try {
             $class = \lang\XPClass::forName($classname);
         } catch (\lang\ClassNotFoundException $e) {
             self::$err->writeLine('*** ', $this->verbose ? $e : $e->getMessage());
             return 1;
         }
     }
     // Check whether class is runnable
     if (!$class->isSubclassOf('lang.Runnable')) {
         self::$err->writeLine('*** ', $class->getName(), ' is not runnable');
         return 1;
     }
     // Usage
     if ($classparams->exists('help', '?')) {
         self::showUsage($class);
         return 0;
     }
     // Load, instantiate and initialize
     $l = Logger::getInstance();
     $pm->hasProperties('log') && $l->configure($pm->getProperties('log'));
     if (class_exists('rdbms\\DBConnection')) {
         // FIXME: Job of XPInjector?
         $cm = ConnectionManager::getInstance();
         $pm->hasProperties('database') && $cm->configure($pm->getProperties('database'));
     }
     // Setup logger context for all registered log categories
     foreach (Logger::getInstance()->getCategories() as $category) {
         if (null === ($context = $category->getContext()) || !$context instanceof EnvironmentAware) {
             continue;
         }
         $context->setHostname(\lang\System::getProperty('host.name'));
         $context->setRunner(nameof($this));
//.........这里部分代码省略.........
开发者ID:johannes85,项目名称:core,代码行数:101,代码来源:Runner.class.php

示例5: non_existant

 public function non_existant()
 {
     ClassLoader::registerPath('@@non-existant@@');
 }
开发者ID:xp-framework,项目名称:core,代码行数:4,代码来源:ClassPathTest.class.php

示例6: run

 /**
  * Main method
  *
  * @param   util.cmd.ParamString params
  * @return  int
  */
 public function run(ParamString $params, Config $config = null)
 {
     // No arguments given - show our own usage
     if ($params->count < 1) {
         $this->selfUsage();
         return 1;
     }
     // Configure properties
     $config || ($config = new Config());
     // Separate runner options from class options
     for ($offset = 0, $i = 0; $i < $params->count; $i++) {
         switch ($params->list[$i]) {
             case '-c':
                 $config->append($params->list[$i + 1]);
                 $offset += 2;
                 $i++;
                 break;
             case '-cp':
                 ClassLoader::registerPath($params->list[$i + 1], null);
                 $offset += 2;
                 $i++;
                 break;
             case '-v':
                 $this->verbose = true;
                 $offset += 1;
                 $i++;
                 break;
             case '-?':
                 $this->selfUsage();
                 return 1;
             case '-l':
                 $this->listCommands();
                 return 1;
             default:
                 break 2;
         }
     }
     // Sanity check
     if (!$params->exists($offset)) {
         self::$err->writeLine('*** Missing classname');
         return 1;
     }
     // Use default path for config if no sources set
     if ($config->isEmpty()) {
         $config->append(is_dir(self::DEFAULT_CONFIG_PATH) ? self::DEFAULT_CONFIG_PATH : '.');
     }
     unset($params->list[-1]);
     $classparams = new ParamString(array_slice($params->list, $offset + 1));
     return $this->runCommand($params->value($offset), $classparams, $config);
 }
开发者ID:xp-framework,项目名称:command,代码行数:56,代码来源:Runner.class.php

示例7: main

 /**
  * Entry point method
  *
  * @param   string[] args
  */
 public static function main(array $args)
 {
     if (empty($args)) {
         return self::usage();
     }
     foreach (ClassLoader::getLoaders() as $loader) {
         if ($loader instanceof JitClassLoader) {
             ClassLoader::removeLoader($loader);
         }
     }
     // Set up compiler
     $compiler = new Compiler();
     $manager = new FileManager();
     $manager->setSourcePaths(\xp::$classpath);
     // Handle arguments
     $profiles = ['default'];
     $emitter = 'php5.5';
     $result = function ($success) {
         return $success ? 0 : 1;
     };
     $files = [];
     $listener = new DefaultDiagnosticListener(Console::$out);
     for ($i = 0, $s = sizeof($args); $i < $s; $i++) {
         if ('-?' === $args[$i] || '--help' === $args[$i]) {
             return self::usage();
         } else {
             if ('-cp' === $args[$i]) {
                 \lang\ClassLoader::registerPath($args[++$i]);
             } else {
                 if ('-sp' === $args[$i]) {
                     $manager->addSourcePath($args[++$i]);
                 } else {
                     if ('-v' === $args[$i]) {
                         $listener = new VerboseDiagnosticListener(Console::$out);
                     } else {
                         if ('-q' === $args[$i]) {
                             $listener = new QuietDiagnosticListener(Console::$out);
                         } else {
                             if ('-t' === $args[$i]) {
                                 $levels = LogLevel::NONE;
                                 foreach (explode(',', $args[++$i]) as $level) {
                                     $levels |= LogLevel::named($level);
                                 }
                                 $compiler->setTrace(create(new LogCategory('xcc'))->withAppender(new ConsoleAppender(), $levels));
                             } else {
                                 if ('-E' === $args[$i]) {
                                     $emitter = $args[++$i];
                                 } else {
                                     if ('-p' === $args[$i]) {
                                         $profiles = explode(',', $args[++$i]);
                                     } else {
                                         if ('-o' === $args[$i]) {
                                             $output = $args[++$i];
                                             $folder = new Folder($output);
                                             $folder->exists() || $folder->create();
                                             $manager->setOutput($folder);
                                         } else {
                                             if ('-N' === $args[$i]) {
                                                 $dir = $args[++$i];
                                                 $manager->addSourcePath($dir);
                                                 $files = array_merge($files, self::fromFolder($dir, false));
                                             } else {
                                                 if (is_dir($args[$i])) {
                                                     $dir = $args[$i];
                                                     $manager->addSourcePath($dir);
                                                     $files = array_merge($files, self::fromFolder($dir, true));
                                                 } else {
                                                     $files[] = new FileSource(new File($args[$i]));
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Check
     if (empty($files)) {
         Console::$err->writeLine('*** No files given (-? will show usage)');
         return 2;
     }
     // Setup emitter
     sscanf($emitter, '%[^0-9]%d.%d', $language, $major, $minor);
     try {
         $emit = \lang\XPClass::forName('xp.compiler.emit.Emitter')->cast(Package::forName('xp.compiler.emit')->getPackage($language)->loadClass(($major ? 'V' . $major . $minor : '') . 'Emitter')->newInstance());
     } catch (\lang\ClassCastException $e) {
         Console::$err->writeLine('*** Not an emitter implementation: ', $e->compoundMessage());
         return 4;
     } catch (\lang\IllegalAccessException $e) {
         Console::$err->writeLine('*** Cannot use emitter named "', $emitter, '": ', $e->compoundMessage());
         return 4;
//.........这里部分代码省略.........
开发者ID:xp-lang,项目名称:compiler,代码行数:101,代码来源:CompileRunner.class.php

示例8:

<?php

namespace xp;

\lang\ClassLoader::registerPath(__DIR__);
开发者ID:xp-framework,项目名称:security,代码行数:5,代码来源:autoload.php

示例9: __construct

 /**
  * Creates a new class loader based template loader
  *
  * @param  string|lang.IClassLoader $base A classloader path or instance
  * @param  string[] $extensions File extensions to check, including leading "."
  */
 public function __construct($arg, $extensions = ['.mustache'])
 {
     parent::__construct($arg instanceof IClassLoader ? $arg : ClassLoader::registerPath($arg), $extensions);
 }
开发者ID:xp-forge,项目名称:mustache,代码行数:10,代码来源:ResourcesIn.class.php


注:本文中的lang\ClassLoader::registerPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。