本文整理汇总了PHP中lang\ClassLoader类的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader类的具体用法?PHP ClassLoader怎么用?PHP ClassLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClassLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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], '.', '\\');
}
}
示例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));
}
}
}');
}
示例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 */ }
}');
}
示例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(); }
}');
}
示例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();
}
}
示例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
;
}
}');
}
示例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));
}
}
}');
}
示例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();
}
}');
}
示例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];
}
示例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(); }
}');
}
示例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 () {
}]);
}
示例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];
}
示例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];
}
示例14: __construct
/**
* Constructor
*
* @param lang.ClassLoader classLoader
*/
public function __construct($classLoader = null)
{
if (null === $classLoader) {
$this->classLoader = ClassLoader::getDefault();
} else {
$this->classLoader = $classLoader;
}
}
示例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 . ' }
}');
}