本文整理汇总了PHP中lang\ClassLoader::defineClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader::defineClass方法的具体用法?PHP ClassLoader::defineClass怎么用?PHP ClassLoader::defineClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lang\ClassLoader
的用法示例。
在下文中一共展示了ClassLoader::defineClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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
;
}
}');
}
示例2: 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 () {
}]);
}
示例3: defineClass
/**
* Helper method
* @param string name
* @param string parent
* @param string[] interfaces
* @return lang.XPClass class
* @throws unittest.AssertionFailedError
*/
protected function defineClass($name, $parent, $interfaces, $bytes)
{
if (class_exists(\xp::reflect($name), false)) {
$this->fail('Class "' . $name . '" may not exist!');
}
return \lang\ClassLoader::defineClass($name, $parent, $interfaces, $bytes);
}
示例4: 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 */ }
}');
}
示例5: 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(); }
}');
}
示例6: 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];
}
示例7: __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();
}
}');
}
示例8: 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));
}
}
}');
}
示例9: 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(); }
}');
}
示例10: 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));
}
}
}');
}
示例11: __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 . ' }
}');
}
示例12: 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"; }
}');
}
示例13: defineVisitor
public static function defineVisitor()
{
self::$visitor = ClassLoader::defineClass('VisitorTest··Visitor', 'xp.compiler.ast.Visitor', [], '{
public $visited= array();
public function visitOne($node) {
$this->visited[]= $node;
return parent::visitOne($node);
}
}');
}
示例14: __static
static function __static()
{
self::$fileStreamAdapter = \lang\ClassLoader::defineClass('FileStreamAdapter', 'io.File', array(), '{
protected $stream= NULL;
public function __construct($stream) { $this->stream= $stream; }
public function exists() { return NULL !== $this->stream; }
public function getURI() { return Streams::readableUri($this->stream); }
public function getInputStream() { return $this->stream; }
}');
}
示例15: __construct
static function __static()
{
self::$fileStreamAdapter = ClassLoader::defineClass('FileStreamAdapter', File::class, [], '{
protected $stream= null;
public function __construct($stream) { $this->stream= $stream; }
public function exists() { return null !== $this->stream; }
public function getURI() { return \\io\\streams\\Streams::readableUri($this->stream); }
public function getInputStream() { return $this->stream; }
}');
}