本文整理汇总了PHP中newinstance函数的典型用法代码示例。如果您正苦于以下问题:PHP newinstance函数的具体用法?PHP newinstance怎么用?PHP newinstance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了newinstance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_contents_read_returns_less_than_size
public function get_contents_read_returns_less_than_size()
{
$f = new File(Streams::readableFd(newinstance(MemoryInputStream::class, ['Test'], ['read' => function ($size = 4096) {
return parent::read(min(1, $size));
}])));
$this->assertEquals('Test', FileUtil::getContents($f));
}
示例2: calls_equals_method_in_maps
public function calls_equals_method_in_maps($value, $outcome)
{
$object = newinstance('lang.Object', [], ['equals' => function ($cmp) {
return 'Test' === $cmp;
}]);
$this->assertEquals($outcome, (new IsEqual(['key' => $object]))->matches($value));
}
示例3: __static
static function __static()
{
self::$UNKNOWN = newinstance(__CLASS__, [0.0, 0.0, []], '{
static function __static() { }
public function toString() { return "com.maxmind.geoip.Location(UNKNOWN)"; }
}');
}
示例4: setUp
/**
* Sets up test case and backups Console::$err stream.
*
*/
public function setUp()
{
$this->cat = (new LogCategory('default'))->withAppender((new ConsoleAppender())->withLayout(newinstance(Layout::class, [], ['format' => function (LoggingEvent $event) {
return implode(' ', $event->getArguments());
}])));
$this->stream = Console::$err->getStream();
}
示例5: compile
/**
* Compile and then run sourcecode
*
* @param string source
* @return lang.Runnable
*/
protected function compile($source)
{
$decl = '
import integrationtests.ArrayExtensions;
class FixturePrimitiveExtensionMethodsIntegrationTest·%d implements Runnable {
public var run() {
%s
}
}';
$emitter = new V54Emitter();
$task = new CompilationTask(new StringSource(sprintf($decl, $this->counter++, $source), self::$syntax, $this->name), new NullDiagnosticListener(), newinstance(FileManager::class, [$this->getClass()->getClassLoader()], '{
protected $cl;
public function __construct($cl) {
$this->cl= $cl;
}
public function findClass($qualified) {
return new FileSource($this->cl->getResourceAsStream("net/xp_lang/tests/integration/src/".strtr($qualified, ".", "/").".xp"));
}
public function write($r, File $target) {
// DEBUG $r->writeTo(Console::$out->getStream());
$r->executeWith(array()); // Defines the class
}
}'), $emitter);
$type = $task->run();
return XPClass::forName($type->name())->newInstance();
}
示例6: noTimeout
public function noTimeout()
{
$r = $this->suite->runTest(newinstance(TestCase::class, ['fixture'], ['#[@test, @limit(time= 0.010)] fixture' => function () {
/* No timeout */
}]));
$this->assertEquals(1, $r->successCount());
}
示例7: setupRecords
/**
* Setup record handlers
*
* @see http://infocenter.sybase.com/help/topic/com.sybase.dc35823_1500/html/uconfig/uconfig111.htm
* @see http://infocenter.sybase.com/help/topic/com.sybase.dc38421_1500/html/ntconfig/ntconfig80.htm
* @return [:rdbms.tds.TdsRecord] handlers
*/
protected function setupRecords()
{
$records[self::T_NUMERIC] = newinstance('rdbms.tds.TdsRecord', array(), '{
public function unmarshal($stream, $field) {
if (-1 === ($len= $stream->getByte()- 1)) return NULL;
$pos= $stream->getByte();
$bytes= $stream->read($len);
if ($i= ($len % 4)) {
$bytes= str_repeat("\\0", 4 - $i).$bytes;
$len+= 4 - $i;
}
for ($n= 0, $m= $pos ? -1 : 1, $i= $len- 4; $i >= 0; $i-= 4, $m= bcmul($m, "4294967296", 0)) {
$n= bcadd($n, bcmul(sprintf("%u", current(unpack("N", substr($bytes, $i, 4)))), $m, 0), 0);
}
return $this->toNumber($n, $field["scale"], $field["prec"]);
}
}');
$records[self::T_DECIMAL] = $records[self::T_NUMERIC];
$records[self::T_BINARY] = newinstance('rdbms.tds.TdsRecord', array(), '{
public function unmarshal($stream, $field) {
if (0 === ($len= $stream->getByte())) return NULL;
$string= $stream->read($len);
return iconv($field["conv"], "iso-8859-1", substr($string, 0, strcspn($string, "\\0")));
}
}');
$records[self::T_IMAGE] = newinstance('rdbms.tds.TdsRecord', array(), '{
public function unmarshal($stream, $field) {
$has= $stream->getByte();
if ($has !== 16) return NULL; // Seems to always be 16 - obsolete?
$stream->read(24); // Skip 16 Byte TEXTPTR, 8 Byte TIMESTAMP
$len= $stream->getLong();
if (0 === $len) return NULL;
$r= $stream->read($len);
// HACK - cannot figure out why UNITEXT is not being returned as such
// but as IMAGE type with different inside layout!
return iconv(
strlen($r) > 1 && "\\0" === $r{1} ? "ucs-2le" : $field["conv"],
"iso-8859-1",
$r
);
}
}');
$records[self::T_VARBINARY] = newinstance('rdbms.tds.TdsRecord', array(), '{
public function unmarshal($stream, $field) {
if (0 === ($len= $stream->getByte())) return NULL;
return iconv($field["conv"], "iso-8859-1", $stream->read($len));
}
}');
$records[self::T_LONGBINARY] = newinstance('rdbms.tds.TdsRecord', array(), '{
public function unmarshal($stream, $field) {
$len= $stream->getLong();
return $stream->getString($len / 2);
}
}');
return $records;
}
示例8: newConnection
protected function newConnection(URL $url)
{
return newinstance(Connection::class, [$url], ['response' => '', 'sent' => null, 'in' => null, 'out' => null, '__construct' => function ($url) {
parent::__construct($url);
$this->_connect($url);
// FIXME: Required for unittest
}, '_connect' => function (URL $url) {
$this->in = new StringReader(new MemoryInputStream($this->response));
$this->out = new StringWriter(new MemoryOutputStream());
}, '_disconnect' => function () {
$this->sent = $this->out->getStream()->getBytes();
$this->in = null;
$this->out = null;
}, 'setResponseBytes' => function ($s) {
$this->in = new StringReader(new MemoryInputStream($s));
$this->response = $s;
}, 'readSentBytes' => function () {
// Case of DISCONNECT
if (null !== $this->sent) {
$sent = $this->sent;
$this->sent = null;
return $sent;
}
return $this->out->getStream()->getBytes();
}, 'clearSentBytes' => function () {
$this->_connect(new URL());
$this->sent = null;
}]);
}
示例9: hashCodeCounter
/** @return lang.Object */
protected function hashCodeCounter()
{
return newinstance(Object::class, [], ['invoked' => 0, 'hashCode' => function () {
$this->invoked++;
return parent::hashCode();
}]);
}
示例10: getNameCase
/**
* Returns a testcase with getName() as test method
*
* @return unittest.TestCase
*/
protected function getNameCase()
{
return newinstance('unittest.TestCase', ['getName'], '{
#[@test]
public function getName($compound= FALSE) { }
}');
}
示例11: __static
static function __static()
{
self::$EQUALS = newinstance(__CLASS__, array(1, 'EQUALS', '='), '{
static function __static() {}
}');
self::$NOT_EQUALS = newinstance(__CLASS__, array(1, 'NOT_EQUALS', '!='), '{
static function __static() {}
}');
self::$GREATER_THAN = newinstance(__CLASS__, array(1, 'GREATER_THAN', '>'), '{
static function __static() {}
}');
self::$GREATER_EQUALS = newinstance(__CLASS__, array(1, 'GREATER_EQUALS', '>='), '{
static function __static() {}
}');
self::$LESS_THAN = newinstance(__CLASS__, array(1, 'LESS_THAN', '<'), '{
static function __static() {}
}');
self::$LESS_EQUALS = newinstance(__CLASS__, array(1, 'LESS_EQUALS', '<='), '{
static function __static() {}
}');
self::$IN = newinstance(__CLASS__, array(1, 'IN', 'in'), '{
static function __static() {}
function forValue($value) {
return $this->op." (".implode(", ", (array)$value).")";
}
}');
self::$NOT_IN = newinstance(__CLASS__, array(1, 'NOT_IN', 'not in'), '{
static function __static() {}
function forValue($value) {
return $this->op." (".implode(", ", (array)$value).")";
}
}');
}
示例12: newinstance
public function newinstance()
{
$runnable = newinstance(Runnable::class, [], ['run' => function () {
return 'Test';
}]);
$this->assertEquals('Test', cast($runnable, Runnable::class)->run());
}
示例13: newinstance
public function newinstance()
{
$runnable = newinstance('lang.Runnable', array(), '{
public function run() { return "RUN"; }
}');
$this->assertEquals('RUN', cast($runnable, 'lang.Runnable')->run());
}
示例14: baseImpl
/**
* Creates underlying base for class loader, e.g. a directory or a .XAR file
*
* @return net.xp_framework.unittest.reflection.ClassFromUriBase
*/
protected static function baseImpl()
{
return newinstance('net.xp_framework.unittest.reflection.ClassFromUriBase', array(), '{
protected $t= NULL;
public function create() {
$this->t= new \\io\\Folder(\\lang\\System::tempDir(), "fsclt");
$this->t->create();
}
public function delete() {
$this->t->unlink();
}
public function newFile($name, $contents) {
$file= new \\io\\File($this->t, $name);
$path= new \\io\\Folder($file->getPath());
$path->exists() || $path->create();
\\io\\FileUtil::setContents($file, $contents);
}
public function path() {
return rtrim($this->t->getURI(), DIRECTORY_SEPARATOR);
}
}');
}
示例15: setUp
/**
* Sets up test case
*/
public function setUp()
{
$this->fixture = newinstance(ImapStore::class, [], ['connect' => [], '_connect' => function ($mbx, $user, $pass, $flags) {
$this->connect = ['mbx' => $mbx, 'user' => $user, 'pass' => $pass, 'flags' => $flags];
return true;
}]);
}