本文整理匯總了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();
}
}