PHP
- 61 ответ
- 0 вопросов
34
Вклад в тег
namespace App\Contract;
interface PaymentInterface
{
public function pay(): string;
}
namespace App\Service;
use App\Contract\PaymentInterface;
class Payment implements PaymentInterface
{
protected $paymentLink;
public function __construct($paymentLink)
{
$this->paymentLink = $paymentLink;
}
public function pay(): string
{
return (string)$this->paymentLink;
}
}
namespace App\Providers;
use App\Contract\PaymentInterface;
use App\Service\Payment;
use Illuminate\Support\ServiceProvider;
class PaymentProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->bind(PaymentInterface::class, function ($app) {
return new Payment(config('app.payment_link'));
});
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
//
}
}
App\Providers\PaymentProvider::class,
'payment_link' => 'https://money.yandex.ru’,
namespace App\Http\Controllers;
use App\Contract\PaymentInterface;
class PaymentController
{
public function getPayment(PaymentInterface $payment)
{
dd($payment->pay());
}
}