本文整理汇总了PHP中lang\XPClass::newInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP XPClass::newInstance方法的具体用法?PHP XPClass::newInstance怎么用?PHP XPClass::newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lang\XPClass
的用法示例。
在下文中一共展示了XPClass::newInstance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toCollection
/**
* Creates a new collector gathering the elements in a collection class
*
* @param lang.XPClass $class
* @return util.data.ICollector
*/
public static function toCollection(XPClass $class)
{
return new Collector(function () use($class) {
return $class->newInstance();
}, function ($result, $arg) {
$result->add($arg);
});
}
示例2: permutationOf
/**
* Add a measurable class
*
* @param lang.XPClass $class
* @param lang.reflect.Method $method
* @param var $source
* @return util.data.Sequence
*/
private function permutationOf($class, $method, $source)
{
if (is_array($source)) {
$seq = Sequence::of($source);
} else {
$seq = Sequence::of($class->getMethod($source)->setAccessible(true)->invoke(null));
}
return $seq->map(function ($args) use($class, $method) {
return $class->newInstance($method, (array) $args);
});
}
示例3: __construct
/**
* Constructor
*
* @param lang.XPClass $scriptlet
* @param string[] args
* @param [:string] env
*/
public function __construct(XPClass $scriptlet, $args, $env = [], $filters = [])
{
if ($scriptlet->hasConstructor()) {
$this->scriptlet = $scriptlet->getConstructor()->newInstance((array) $args);
} else {
$this->scriptlet = $scriptlet->newInstance();
}
foreach ($filters as $filter) {
$this->scriptlet->filter($filter);
}
$this->scriptlet->init();
$this->env = $env;
}
示例4: newInstance
/**
* Creates a new instance of a given class. If the constructor uses
* injection, the arguments are compiled from the relevant annotations.
* Otherwise, optional constructor arguments may be passed.
*
* @param lang.XPClass $class
* @param [:var] $named Named arguments
* @return var
* @throws inject.ProvisionException
*/
public function newInstance(XPClass $class, $named = [])
{
if ($class->hasConstructor()) {
$constructor = $class->getConstructor();
try {
return $constructor->newInstance($this->args($constructor, $named));
} catch (TargetInvocationException $e) {
throw new ProvisionException('Error creating an instance of ' . $class->getName(), $e->getCause());
} catch (Throwable $e) {
throw new ProvisionException('Error creating an instance of ' . $class->getName(), $e);
}
} else {
return $class->newInstance();
}
}