本文整理汇总了PHP中lang\ClassLoader类的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader类的具体用法?PHP ClassLoader怎么用?PHP ClassLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClassLoader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: dummyConnectionClass
public static function dummyConnectionClass()
{
self::$conn = \lang\ClassLoader::defineClass('RestClientExecutionTest_Connection', 'peer.http.HttpConnection', array(), '{
protected $result= NULL;
protected $exception= NULL;
public function __construct($status, $body, $headers) {
parent::__construct("http://test");
if ($status instanceof Throwable) {
$this->exception= $status;
} else {
$this->result= "HTTP/1.1 ".$status."\\r\\n";
foreach ($headers as $name => $value) {
$this->result.= $name.": ".$value."\\r\\n";
}
$this->result.= "\\r\\n".$body;
}
}
public function send(HttpRequest $request) {
if ($this->exception) {
throw $this->exception;
} else {
return new HttpResponse(new MemoryInputStream($this->result));
}
}
}');
}
开发者ID:melogamepay,项目名称:xp-framework,代码行数:28,代码来源:RestClientExecutionTest.class.php
示例3: defineLayout
public static function defineLayout()
{
self::$layout = ClassLoader::defineClass(self::class . '_Layout', Object::class, [WebLayout::class], '{
public function mappedApplications($profile= null) { /* Intentionally empty */ }
public function staticResources($profile= null) { /* Intentionally empty */ }
}');
}
开发者ID:xp-framework,项目名称:scriptlet,代码行数:7,代码来源:SourceTest.class.php
示例4: defineExiterClass
public static function defineExiterClass()
{
self::$exiterClass = \lang\ClassLoader::defineClass('net.xp_framework.unittest.core.Exiter', 'lang.Object', array(), '{
public function __construct() { throw new SystemExit(0); }
public static function doExit() { new self(); }
}');
}
开发者ID:melogamepay,项目名称:xp-framework,代码行数:7,代码来源:SystemExitTest.class.php
示例5: main
/**
* Main
*
* Exitcodes used:
* <ul>
* <li>127: Archive referenced in -xar [...] does not exist</li>
* <li>126: No manifest or manifest does not have a main-class</li>
* </ul>
*
* @see http://tldp.org/LDP/abs/html/exitcodes.html
* @param string[] args
* @return int
*/
public static function main(array $args)
{
// Open archive
$f = new File(array_shift($args));
if (!$f->exists()) {
Console::$err->writeLine('*** Cannot find archive ' . $f->getURI());
return 127;
}
// Register class loader
$cl = \lang\ClassLoader::registerLoader(new \lang\archive\ArchiveClassLoader(new Archive($f)));
if (!$cl->providesResource(self::MANIFEST)) {
Console::$err->writeLine('*** Archive ' . $f->getURI() . ' does not have a manifest');
return 126;
}
// Load manifest
$pr = Properties::fromString($cl->getResource(self::MANIFEST));
if (null === ($class = $pr->readString('archive', 'main-class', null))) {
Console::$err->writeLine('*** Archive ' . $f->getURI() . '\'s manifest does not have a main class');
return 126;
}
// Run main()
try {
return \lang\XPClass::forName($class, $cl)->getMethod('main')->invoke(null, [$args]);
} catch (\lang\reflect\TargetInvocationException $e) {
throw $e->getCause();
}
}
开发者ID:johannes85,项目名称:core,代码行数:40,代码来源:Xar.class.php
示例6: __static
static function __static()
{
self::$rewriter = \lang\ClassLoader::defineClass('InliningOptimization··Rewriter', 'xp.compiler.ast.Visitor', [], '{
protected $replacements;
protected $protect;
public function __construct($replacements, $protect) {
$this->replacements= $replacements;
$this->protect= $protect;
}
protected function visitMethodCall(\\xp\\compiler\\ast\\MethodCallNode $node) {
if ($node->name === $this->protect) $node->inlined= true;
return parent::visitMethodCall($node);
}
protected function visitStaticMethodCall(\\xp\\compiler\\ast\\StaticMethodCallNode $node) {
if ($node->name === $this->protect) $node->inlined= true;
return parent::visitStaticMethodCall($node);
}
protected function visitVariable(\\xp\\compiler\\ast\\VariableNode $node) {
return isset($this->replacements[$node->name])
? clone $this->replacements[$node->name]
: $node
;
}
}');
}
开发者ID:xp-lang,项目名称:compiler,代码行数:29,代码来源:InliningOptimization.class.php
示例7: dummyConnectionClass
public static function dummyConnectionClass()
{
self::$conn = ClassLoader::defineClass('EndpointExecutionTest_Connection', 'peer.http.HttpConnection', [], '{
private $result, $exception;
public function __construct($status, $body, $headers) {
parent::__construct("http://test");
if ($status instanceof \\lang\\Throwable) {
$this->exception= $status;
} else {
$this->result= "HTTP/1.1 ".$status."\\r\\n";
foreach ($headers as $name => $value) {
$this->result.= $name.": ".$value."\\r\\n";
}
$this->result.= "\\r\\n".$body;
}
}
public function send(\\peer\\http\\HttpRequest $request) {
if ($this->exception) {
throw $this->exception;
} else {
return new \\peer\\http\\HttpResponse(new \\io\\streams\\MemoryInputStream($this->result));
}
}
}');
}
开发者ID:xp-framework,项目名称:rest,代码行数:27,代码来源:ExecutionTest.class.php
示例8: __construct
static function __static()
{
// For singletonInstance test
ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousSingleton', 'lang.Object', array(), '{
protected static $instance= NULL;
static function getInstance() {
if (!isset(self::$instance)) self::$instance= new AnonymousSingleton();
return self::$instance;
}
}');
// For returnNewObject and returnNewObjectViaReflection tests
ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousList', 'lang.Object', array(), '{
public function __construct() {
\\net\\xp_framework\\unittest\\core\\ReferencesTest::registry("list", $this);
}
}');
ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousFactory', 'lang.Object', array(), '{
static function factory() {
return new AnonymousList();
}
}');
ClassLoader::defineClass('net.xp_framework.unittest.core.AnonymousNewInstanceFactory', 'lang.Object', array(), '{
static function factory() {
return XPClass::forName("net.xp_framework.unittest.core.AnonymousList")->newInstance();
}
}');
}
开发者ID:melogamepay,项目名称:xp-framework,代码行数:28,代码来源:ReferencesTest.class.php
示例9: create
/**
* Creates a new instance creation fluent interface for a given class
*
* @param lang.mirrors.TypeMirror|lang.XPClass|string $type
* @return lang.XPClass
*/
public static final function typeOf($type)
{
$mirror = $type instanceof TypeMirror ? $type : new TypeMirror($type);
$type = $mirror->name();
if (!isset(self::$creations[$type])) {
if (!$mirror->kind()->isClass() || $mirror->modifiers()->isAbstract()) {
throw new IllegalArgumentException('Class ' . $type . ' is not instantiable');
}
$constructor = $mirror->constructor();
if (!$constructor->present()) {
throw new IllegalArgumentException('Class ' . $type . ' does not have a constructor');
}
$setters = $args = '';
foreach ($constructor->parameters() as $parameter) {
$name = $parameter->name();
if ($parameter->isOptional()) {
$setters .= 'public $' . $name . '= ' . var_export($parameter->defaultValue(), true) . ';';
} else {
$setters .= 'public $' . $name . ';';
}
$setters .= "/**\n * @param " . $parameter->type() . "\n * @return self\n*/";
$setters .= 'public function ' . $name . '($value) { $this->' . $name . '= $value; return $this; }';
$args .= ', $this->' . $name;
}
self::$creations[$type] = ClassLoader::defineClass($type . 'Creation', 'lang.partial.InstanceCreation', [], '{
/** @return ' . $mirror->name() . ' */
public function create() { return new \\' . $mirror->reflect->name . '(' . substr($args, 2) . '); }
' . $setters . '
}');
}
return self::$creations[$type];
}
开发者ID:xp-forge,项目名称:partial,代码行数:38,代码来源:InstanceCreationV7.class.php
示例10: defineExiterClass
public static function defineExiterClass()
{
self::$exiterClass = ClassLoader::defineClass('net.xp_framework.unittest.core.Exiter', Object::class, [], '{
public function __construct() { throw new \\lang\\SystemExit(0); }
public static function doExit() { new self(); }
}');
}
开发者ID:xp-framework,项目名称:core,代码行数:7,代码来源:SystemExitTest.class.php
示例11: defineCommandClass
public static function defineCommandClass()
{
self::$class = ClassLoader::defineClass('util.cmd.unittest.BatchImport', Command::class, [], ['run' => function () {
}]);
self::$global = ClassLoader::defineClass('BatchImport', Command::class, [], ['run' => function () {
}]);
}
开发者ID:xp-framework,项目名称:command,代码行数:7,代码来源:CommandsTest.class.php
示例12: define
/**
* Defines a type
*
* @param string $declaration
* @param string[] $extends
* @return lang.XPClass
*/
protected function define($declaration, $extends = [Object::class])
{
if (!isset(self::$fixtures[$declaration])) {
$definition = ['kind' => 'class', 'extends' => $extends, 'implements' => [], 'use' => [], 'imports' => [Identity::class => null]];
self::$fixtures[$declaration] = ClassLoader::defineType(nameof($this) . sizeof(self::$fixtures), $definition, $declaration);
}
return self::$fixtures[$declaration];
}
开发者ID:xp-forge,项目名称:mirrors,代码行数:15,代码来源:TypeDefinition.class.php
示例13: type
/**
* Defines an anonymous type
*
* @param string $decl Type declaration
* @param int $modifiers
* @return lang.XPClass
*/
protected function type($decl = null, $modifiers = '')
{
if (!isset(self::$fixtures[$decl])) {
$definition = ['modifiers' => $modifiers, 'kind' => 'class', 'extends' => [Object::class], 'implements' => [], 'use' => [CompareTo::class], 'imports' => [Value::class => null]];
self::$fixtures[$decl] = ClassLoader::defineType(get_class($this) . sizeof(self::$fixtures), $definition, $decl);
}
return self::$fixtures[$decl];
}
开发者ID:xp-framework,项目名称:core,代码行数:15,代码来源:TypeDefinition.class.php
示例14: __construct
/**
* Constructor
*
* @param lang.ClassLoader classLoader
*/
public function __construct($classLoader = null)
{
if (null === $classLoader) {
$this->classLoader = ClassLoader::getDefault();
} else {
$this->classLoader = $classLoader;
}
}
开发者ID:johannes85,项目名称:core,代码行数:13,代码来源:MockProxyBuilder.class.php
示例15: __construct
/**
* Constructor
*
* @param string bytes method sourcecode
*/
public function __construct($bytes)
{
$name = 'xp.unittest.DynamicallyGeneratedTestCase·' . self::$uniqId++;
$this->testClass = \lang\ClassLoader::defineClass($name, 'unittest.TestCase', array(), '{
#[@test]
public function run() { ' . $bytes . ' }
}');
}
开发者ID:melogamepay,项目名称:xp-framework,代码行数:13,代码来源:EvaluationSource.class.php
示例16: testCasesWith
/**
* Get all test cases
*
* @param var[] arguments
* @return unittest.TestCase[]
*/
public function testCasesWith($arguments)
{
$uri = $this->file->getURI();
$cl = \lang\ClassLoader::getDefault()->findUri($uri);
if (is(null, $cl)) {
throw new IllegalArgumentException('Cannot load class from ' . $this->file->toString());
}
return $this->testCasesInClass($cl->loadUri($uri), $arguments);
}
开发者ID:melogamepay,项目名称:xp-framework,代码行数:15,代码来源:ClassFileSource.class.php
示例17: fixture
/**
* Creates a fixrture
*
* @return util.PropertyManager
*/
private function fixture()
{
$class = ClassLoader::getDefault()->defineClass('NonSingletonPropertyManager', PropertyManager::class, [], '{
public static function newInstance() {
return new self();
}
}');
return $class->getMethod('newInstance')->invoke(null);
}
开发者ID:johannes85,项目名称:core,代码行数:14,代码来源:PropertyManagerTest.class.php
示例18: defineResult
public static function defineResult()
{
self::$result = \lang\ClassLoader::defineClass('FileManagerTestEmitterResult', 'lang.Object', ['xp.compiler.emit.EmitterResult'], '{
protected $type= null;
public function __construct($name) { $this->type= new \\xp\\compiler\\types\\TypeReference(new \\xp\\compiler\\types\\TypeName($name)); }
public function type() { return $this->type; }
public function extension() { return ".test"; }
}');
}
开发者ID:xp-lang,项目名称:compiler,代码行数:9,代码来源:FileManagerTest.class.php
示例19: main
/**
* Main
*
* @param string[] args
* @return int
*/
public static function main(array $args)
{
Console::writeLinef('XP %s { PHP %s & ZE %s } @ %s', \xp::version(), phpversion(), zend_version(), php_uname());
Console::writeLine('Copyright (c) 2001-2015 the XP group');
foreach (\lang\ClassLoader::getLoaders() as $delegate) {
Console::writeLine($delegate->toString());
}
return 1;
}
开发者ID:johannes85,项目名称:core,代码行数:15,代码来源:Version.class.php
示例20: __construct
/**
* Creates a new class source
*
* @param string $class Dotted fully qualified name
* @throws lang.ClassFormatException
*/
public function __construct($class)
{
$cl = ClassLoader::getDefault()->findClass($class);
if ($cl instanceof IClassLoader) {
$this->tokenize($cl->loadClassBytes($class), $class);
} else {
$this->tokens = null;
}
}
开发者ID:xp-forge,项目名称:mirrors,代码行数:15,代码来源:ClassSource.class.php
注:本文中的lang\ClassLoader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论