我正在处理的作曲家软件包有问题.它实现了可计费"特征.
I am having problems with a composer package I am dealing with. It implements a trait Billable.
trait Billable { /** * Update the payment method token for all of the user's subscriptions. * * @param string $token * @return void */ protected function updateSubscriptionsToPaymentMethod($token) { foreach ($this->subscriptions as $subscription) { if ($subscription->active()) { BraintreeSubscription::update($subscription->braintree_id, [ 'paymentMethodToken' => $token, ]); } } } }我正在尝试在我的课程中覆盖此方法
I am trying to override this method in my class
class Organisation extends Model { use Billable; /** * Update the payment method token for all of the user's subscriptions. * * @param string $token * @return void */ protected function updateSubscriptionsToPaymentMethod($token) { foreach ($this->subscriptions as $subscription) { if ($subscription->active()) { BrntreeSubscription::update($subscription->braintree_id, [ 'paymentMethodToken' => $token, ]); } } } }但是该方法没有被覆盖.作为测试,我否决了一些公共职能,并且它们运转良好,这是特质的限制吗?我试图在网上找到答案,但是很简短.
But the method is not overridden. As a test I overrode some of the public functions and they work fine, it this a limitation of traits? I have tried to find the answer online but have come up short.
我试图覆盖此功能,因为我需要自定义BraintreeSubscription类的行为.
I am trying to override this function because I need to customize the behaviour of the BraintreeSubscription class.
任何帮助将不胜感激.
推荐答案在您的类中,您可以在函数名称之前做以下通知T,您可以将其更改为真正的别名.
in your class you could do the following notice the T before the function name you may change this to be aliased as anything really.
use billable { updateSubscriptionsToPaymentMethod as tUpdateSubscriptionsToPaymentMethod; }然后只需在类中添加所需的功能:
then simply in the class add the desired function:
public function updateSubscriptionsToPaymentMethod(){ ... }更多推荐
PHP Trait重写保护的Trait方法
发布评论