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


PHP ClassLoader::defineClass方法代码示例

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


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

示例1: 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 ClassLoader::defineClass($name, $parent, $interfaces, $bytes);
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:16,代码来源:RuntimeClassDefinitionTest.class.php

示例2: defineExiterClass

 public static function defineExiterClass()
 {
     self::$exiterClass = 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:Gamepay,项目名称:xp-framework,代码行数:7,代码来源:SystemExitTest.class.php

示例3: __static

    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(), '{
        function __construct() {
          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:Gamepay,项目名称:xp-framework,代码行数:28,代码来源:ReferencesTest.class.php

示例4: __static

 static function __static()
 {
     ClassLoader::defineClass('net.xp_framework.unittest.core.TypeHintedClass', 'lang.Object', array(), '{
     public static function passObject(Generic $o) { return $o; }
     public static function passNullable(Generic $o= NULL) { return $o; }
   }');
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:7,代码来源:TypeHintsTest.class.php

示例5: dummyConnectionClass

    public static function dummyConnectionClass()
    {
        self::$conn = 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:Gamepay,项目名称:xp-framework,代码行数:28,代码来源:RestClientExecutionTest.class.php

示例6: __construct

 /**
  * Constructor
  *
  * @param   string bytes method sourcecode
  */
 public function __construct($bytes)
 {
     $name = 'xp.unittest.DynamicallyGeneratedTestCase·' . self::$uniqId++;
     $this->testClass = ClassLoader::defineClass($name, 'unittest.TestCase', array(), '{
     #[@test] 
     public function run() { ' . $bytes . ' }
   }');
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:13,代码来源:EvaluationSource.class.php

示例7: __static

 static function __static()
 {
     self::$fileStreamAdapter = 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; }
   }');
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:10,代码来源:FileBasedPropertiesTest.class.php

示例8: map_of_string_to_object

    public function map_of_string_to_object()
    {
        ClassLoader::defineClass('GenericsBCTest_Map', 'lang.Object', array(), '{
        public $__generic;

        public function getClassName() {
          return "Map<".$this->__generic[0].", ".$this->__generic[1].">";
        }
      }');
        $this->assertEquals('Map<String, Object>', create('new GenericsBCTest_Map<String, Object>')->getClassName());
    }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:11,代码来源:GenericsBCTest.class.php

示例9: registerTransport

    public static function registerTransport()
    {
        HttpTransport::register('test', ClassLoader::defineClass('TestHttpTransport', 'peer.http.HttpTransport', array(), '{
        public $host, $port, $arg;

        public function __construct(URL $url, $arg) {
          $this->host= $url->getHost();
          $this->port= $url->getPort(80);
          $this->arg= $arg;
        }
        
        public function send(HttpRequest $request, $timeout= 60, $connecttimeout= 2.0) {
          // Not implemented
        }
      }'));
    }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:16,代码来源:HttpTransportTest.class.php

示例10: defineMockSocket

    public static function defineMockSocket()
    {
        self::$mockSocket = ClassLoader::defineClass('net.xp_framework.unittest.remote.MockSocket', 'lang.Object', array(), '{
        public function __construct($bytes) {
          $this->bytes= $bytes;
          $this->offset= 0;
        }

        public function readBinary($size= 8192) {
          if ($this->offset > strlen($this->bytes)) return FALSE;
          $chunk= substr($this->bytes, $this->offset, $size);
          $this->offset+= strlen($chunk);
          return $chunk;
        }
      }');
    }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:16,代码来源:ByteCountedStringTest.class.php

示例11: requestEchoingConnectionClass

 public static function requestEchoingConnectionClass()
 {
     self::$conn = ClassLoader::defineClass('RestClientSendTest_Connection', 'peer.http.HttpConnection', array(), '{
     public function __construct() {
       parent::__construct("http://test");
     }
     
     public function send(HttpRequest $request) {
       $str= $request->getRequestString();
       return new HttpResponse(new MemoryInputStream(sprintf(
         "HTTP/1.0 200 OK\\r\\nContent-Type: text/plain\\r\\nContent-Length: %d\\r\\n\\r\\n%s",
         strlen($str),
         $str
       )));
     }
   }');
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:17,代码来源:RestClientSendTest.class.php

示例12: __static

 static function __static()
 {
     $self = new XPClass(__CLASS__);
     foreach (hash_algos() as $algo) {
         MessageDigest::register($algo, $self);
     }
     // Overwrite crc32b implementation if a buggy implementation is detected.
     // Workaround for http://bugs.php.net/bug.php?id=45028
     if ('0a1cb779' === hash('crc32b', 'AAAAAAAA')) {
         MessageDigest::register('crc32b', ClassLoader::defineClass(__CLASS__ . '·CRC32bDigestImpl', $self->getName(), array(), '{
       public function doFinal() {
         $n= hexdec(hash_final($this->handle));
         return sprintf("%08x", (($n & 0xFF) << 24) + (($n & 0xFF00) << 8) + (($n & 0xFF0000) >> 8) + (($n >> 24) & 0xFF));
       }
     }'));
     }
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:17,代码来源:DefaultDigestImpl.class.php

示例13: mockSocket

    public static function mockSocket()
    {
        self::$sock = ClassLoader::defineClass('net.xp_framework.unittest.rdbms.tds.MockTdsSocket', 'peer.Socket', array(), '{
        public $bytes;
        protected $offset= 0;
        
        public function __construct($bytes= "") {
          $this->bytes= $bytes;
        }

        public function write($bytes) {
          $this->bytes.= $bytes;
        }
        
        public function readBinary($l) {
          $chunk= substr($this->bytes, $this->offset, $l);
          $this->offset+= $l;
          return $chunk;
        }
      }');
    }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:21,代码来源:TdsDataStreamTest.class.php

示例14: static_member_excluded

 public function static_member_excluded()
 {
     $class = ClassLoader::defineClass('RestConversionTest_StaticMemberExcluded', 'lang.Object', array(), '{
     public $name;
     public static $instance= NULL;
   }');
     $this->assertNull($this->fixture->convert($class, array('name' => 'Test', 'instance' => 'Value'))->getClass()->getField('instance')->get(NULL));
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:8,代码来源:RestDeserializerConversionTest.class.php

示例15: defineScriptlets

    public static function defineScriptlets()
    {
        self::$errorScriptlet = ClassLoader::defineClass('ErrorScriptlet', 'scriptlet.HttpScriptlet', array('util.log.Traceable'), '{
        protected function _request() {
          $req= parent::_request();
          $req->method= "GET";
          $req->env["SERVER_PROTOCOL"]= "HTTP/1.1";
          $req->env["REQUEST_URI"]= "/error";
          $req->env["HTTP_HOST"]= "localhost";
          return $req;
        }
        
        public function setTrace($cat) {
          $cat->debug("Injected", $cat->getClassName());
        }
        
        protected function _setupRequest($request) {
          // Intentionally empty
        }
        
        public function doGet($request, $response) {
          throw new IllegalAccessException("No shoes, no shorts, no service");
        }
      }');
        self::$welcomeScriptlet = ClassLoader::defineClass('WelcomeScriptlet', 'scriptlet.HttpScriptlet', array(), '{
        protected function _request() {
          $req= parent::_request();
          $req->method= "GET";
          $req->env["SERVER_PROTOCOL"]= "HTTP/1.1";
          $req->env["REQUEST_URI"]= "/welcome";
          $req->env["HTTP_HOST"]= "localhost";
          return $req;
        }
        
        protected function _setupRequest($request) {
          // Intentionally empty
        }
        
        public function doGet($request, $response) {
          $response->write("<h1>Welcome, we are open</h1>");
        }
      }');
        self::$xmlScriptlet = ClassLoader::defineClass('XmlScriptletImpl', 'scriptlet.xml.XMLScriptlet', array(), '{
        protected function _request() {
          $req= parent::_request();
          $req->method= "GET";
          $req->env["SERVER_PROTOCOL"]= "HTTP/1.1";
          $req->env["REQUEST_URI"]= "/welcome";
          $req->env["HTTP_HOST"]= "localhost";
          return $req;
        }

        protected function _response() {
          $res= parent::_response();
          $stylesheet= create(new Stylesheet())
            ->withEncoding("iso-8859-1")
            ->withOutputMethod("xml")
            ->withTemplate(create(new XslTemplate())->matching("/")
              ->withChild(create(new Node("h1"))
                ->withChild(new Node("xsl:value-of", NULL, array("select" => "/formresult/result")))
              )
            )
          ;
          $res->setStylesheet($stylesheet, XSLT_TREE);
          return $res;
        }
        
        protected function _setupRequest($request) {
          // Intentionally empty
        }
        
        public function doGet($request, $response) {
          $response->addFormresult(new Node("result", "Welcome, we are open"));
        }
      }');
        self::$debugScriptlet = ClassLoader::defineClass('DebugScriptlet', 'scriptlet.HttpScriptlet', array(), '{
        protected $title, $date;

        public function __construct($title, $date) {
          $this->title= $title;
          $this->date= $date;
        }
        
        protected function _request() {
          $req= parent::_request();
          $req->method= "GET";
          $req->env["SERVER_PROTOCOL"]= "HTTP/1.1";
          $req->env["REQUEST_URI"]= "/debug";
          $req->env["HTTP_HOST"]= "localhost";
          return $req;
        }
        
        protected function _setupRequest($request) {
          // Intentionally empty
        }
        
        public function doGet($request, $response) {
          $response->write("<h1>".$this->title." @ ".$this->date."</h1>");

          $response->write("<ul>");
//.........这里部分代码省略.........
开发者ID:Gamepay,项目名称:xp-framework,代码行数:101,代码来源:RunnerTest.class.php


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