PHP Trait重写保护的Trait方法

编程入门 行业动态 更新时间:2024-10-28 12:21:11
本文介绍了PHP Trait重写保护的Trait方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在处理的作曲家软件包有问题.它实现了可计费"特征.

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方法

本文发布于:2023-05-29 21:32:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/353293.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   方法   PHP   Trait

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!