<?php
$json = '{
"response":
{
"GeoObjectCollection":
{
"metaDataProperty":
{
"GeocoderResponseMetaData":
{
"Point":
{
"pos": "30.245018 59.844872"
},
"request": "30.245018 59.844872",
"results": "1",
"found": "1"
}
},
"featureMember": [
{
"GeoObject":
{
"metaDataProperty":
{
"GeocoderMetaData":
{
"precision": "other",
"text": "Россия, Санкт-Петербург, Кировский район, муниципальный округ Дачное",
"kind": "district",
"Address":
{
"country_code": "RU",
"formatted": "Россия, Санкт-Петербург, Кировский район, муниципальный округ Дачное",
"Components": [
{
"kind": "country",
"name": "Россия"
},
{
"kind": "province",
"name": "Северо-Западный федеральный округ"
},
{
"kind": "province",
"name": "Санкт-Петербург"
},
{
"kind": "locality",
"name": "Санкт-Петербург"
},
{
"kind": "district",
"name": "Кировский район"
},
{
"kind": "district",
"name": "муниципальный округ Дачное"
}]
},
"AddressDetails":
{
"Country":
{
"AddressLine": "Россия, Санкт-Петербург, Кировский район, муниципальный округ Дачное",
"CountryNameCode": "RU",
"CountryName": "Россия",
"AdministrativeArea":
{
"AdministrativeAreaName": "Санкт-Петербург",
"Locality":
{
"LocalityName": "Санкт-Петербург",
"DependentLocality":
{
"DependentLocalityName": "Кировский район",
"DependentLocality":
{
"DependentLocalityName": "муниципальный округ Дачное"
}
}
}
}
}
}
}
},
"name": "муниципальный округ Дачное",
"description": "Кировский район, Санкт-Петербург, Россия",
"boundedBy":
{
"Envelope":
{
"lowerCorner": "30.208061 59.831309",
"upperCorner": "30.269183 59.858702"
}
},
"Point":
{
"pos": "30.240194 59.845749"
}
}
}]
}
}
}';
$result = json_decode($json, true);
if (isset($result['response']['GeoObjectCollection']['featureMember'])) {
foreach($result['response']['GeoObjectCollection']['featureMember'] as $featureMember) {
if(isset($featureMember['GeoObject']['metaDataProperty']['GeocoderMetaData']['Address'])) {
$address = $featureMember['GeoObject']['metaDataProperty']['GeocoderMetaData']['Address'];
if(isset($address['Components']) && is_array($address['Components'])) {
foreach ($address['Components'] as $component) {
echo ($component['kind'] ."-". $component['name']) . "\n\r";
}
}
}
}
}
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());
}
}