本文整理汇总了PHP中lang\XPClass::getConstructor方法的典型用法代码示例。如果您正苦于以下问题:PHP XPClass::getConstructor方法的具体用法?PHP XPClass::getConstructor怎么用?PHP XPClass::getConstructor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lang\XPClass
的用法示例。
在下文中一共展示了XPClass::getConstructor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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;
}
示例2: construct
/**
* Entry point: Invoke constructor
*
* @param lang.XPClass
* @return net.xp_framework.unittest.reflection.ProtectedAccessibilityFixture
*/
public static function construct(\lang\XPClass $class)
{
return $class->getConstructor()->newInstance([]);
}
示例3: 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();
}
}