本文整理匯總了PHP中lang\XPClass::hasConstructor方法的典型用法代碼示例。如果您正苦於以下問題:PHP XPClass::hasConstructor方法的具體用法?PHP XPClass::hasConstructor怎麽用?PHP XPClass::hasConstructor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類lang\XPClass
的用法示例。
在下文中一共展示了XPClass::hasConstructor方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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();
}
}