Мне нужно добавить новые функции в пользовательский пакет Symfony, который мой коллега ранее разработал. Чтобы работать с этим пакетом, я установил его в Symfony Base_App через композитор. Во время установки была ошибка, и в одном из файлов использовалось неправильное пространство имен. Вот пример того, как сейчас установлен пакет: < /p>
return [
// Custom\NotificationBundle\NotificationBundle::class => ['all' => true],
Custom\NotificationBundle\DependencyInjection\CustomNotificationBundle::class => ['all' => true],
];
< /code>
Во время работы с этим пакетом я сталкиваюсь с ошибкой: < /p>
Определение для "custom.notifo.service" не имеет класса. Если вы собираетесь динамически ввести эту службу во время выполнения, отметьте ее как Synthetic = true. Если это абстрактное определение, используемое исключительно по определениям детей, добавьте Abstract = true, в противном случае укажите класс, чтобы избавиться от этой ошибки.
Ошибка отображается, когда я пытаюсь запустить bin/console config: summ notifo . />
services:
custom.notifo.service:
class: Custom\NotificationBundle\Service\NotifoService
arguments:
- '%custom.notifo.host%'
- '%custom.notifo.appid%'
- '%custom.notifo.apikey%'
- '@custom.notifo.requests_service'
- '%custom.notifo.sms.api_id%'
- '%custom.notifo.sms.sender_id%'
- '@logger'
public: true
autoconfigure: false
< /code>
bundle также имеет тесты и сервисы. Yaml выглядит так же: < /p>
services:
_defaults:
autowire: true
autoconfigure: true
custom.notifo.service:
class: Custom\NotificationBundle\Service\NotifoService
arguments: [ '%host%', '%appId%', '%apiKey%' , '@custom.notifo.requests_service', '%apiId%', '%senderId%', '@logger' ]
public: true
< /code>
Конфигурация выглядит так: < /p>
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('custom_notifo');
$treeBuilder->getRootNode()
->children()
->arrayNode('notifo')
->children()
->scalarNode('appid')
->defaultValue('custom')->end()
->scalarNode('apikey')
->defaultValue('custom')->end()
->scalarNode('host')
->defaultValue('custom')->end()
->arrayNode('sms')
->children()
->scalarNode('api_id')->isRequired()->cannotBeEmpty()->end()
->scalarNode('sender_id')->isRequired()->cannotBeEmpty()->end()
->end()
->end()
->end();
return $treeBuilder;
}
public function getName(){
return 'custom_notifo';
}
}
< /code>
Пакет выглядит следующим образом: < /p>
namespace Custom\NotificationBundle\DependencyInjection;
class CustomNotificationBundle extends Bundle
{
protected string $extensionAlias = 'custom_notifo';
public function build(ContainerBuilder $container): void
{
parent::build($container);
$extension = new CustomNotificationExtension();
$container->registerExtension($extension);
}
}
< /code>
У меня также есть этот класс < /p>
namespace Custom\NotificationBundle;
class NotificationBundle extends Bundle
{
}
< /code>
Я никогда раньше не работал с написанием пакета, поэтому я не знаю, что делать. Коллега сказал, что пакет работает, существует функция для отправки электронных писем через Notifo. < /P>
NotifoService: < /p>
namespace Webant\NotificationBundle\Service;
class NotifoService
{
private $eventsUrl;
private $usersUrl;
private string $smsApiId;
private string $smsSenderId;
private LoggerInterface $logger;
public function __construct(
private string $host,
private string $appId,
private string $apiKey,
private RequestsService $requests,
string $smsApiId,
string $smsSenderId,
LoggerInterface $logger
) {
$this->eventsUrl = 'https://'.$this->host .'/api/apps/'. $this->appId. '/events';
$this->usersUrl = 'https://' . $this->host . '/api/apps/' . $this->appId . '/users';
$this->smsApiId = $smsApiId;
$this->smsSenderId = $smsSenderId;
$this->logger = $logger;
}
public function sendNotification(Mail $mail): int{
$this->checkValidateNotification($mail);
if (!array_key_exists('templateName', get_object_vars($mail)) || $mail->templateName === ''){
throw new BadRequestException('Темплейт не может быть пустым', 400);
}
$notifoBody = new NotificationObject($mail);
$data = $notifoBody->requests;
return $this->notifoPostRequest($data, $this->eventsUrl);
}
public function notifoPostRequest(array $data, string $url): int{
$httpClient = HttpClient::create();
$options = $this->requests->makeOptions($this->host, $this->apiKey, $data);
$response = $httpClient->request(
Request::METHOD_POST,
$url,
$options
);
return $response->getStatusCode();
}
}
< /code>
namespace Custom\NotificationBundle\DependencyInjection;
class CustomNotificationExtension extends Extension
{
private $configuration;
public function load(array $configs, ContainerBuilder $container): void
{
$this->configuration = new Configuration();
$config = $this->processConfiguration($this->configuration, $configs);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('services.yaml');
$container->setParameter('custom.notifo.appid', $config['notifo']['appid']);
$container->setParameter('custom.notifo.apikey', $config['notifo']['apikey']);
$container->setParameter('custom.notifo.host', $config['notifo']['host']);
$container->setParameter('custom.notifo.sms.api_id', $config['notifo']['sms']['api_id']);
$container->setParameter('custom.notifo.sms.sender_id', $config['notifo']['sms']['sender_id']);
$container->register('custom.notifo.service')
->addArgument($config['notifo']['host'])
->addArgument($config['notifo']['appid'])
->addArgument($config['notifo']['apikey'])
->addArgument($config['notifo']['sms']['api_id'])
->addArgument($config['notifo']['sms']['sender_id']);
$container->register('custom.notifo.user_service')
->addArgument($config['notifo']['host'])
->addArgument($config['notifo']['appid']);
$container->register('custom.notifo.topic_service')
->addArgument($config['notifo']['host'])
->addArgument($config['notifo']['appid']);
$container->register('custom.notifo.mobile_push_service')
->addArgument($config['notifo']['host'])
->addArgument($config['notifo']['appid']);
}
public function setConfiguration(Configuration $configuration)
{
$this->configuration = $configuration;
}
public function getAlias(): string
{
return 'custom_notifo';
}
public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface
{
return $this->configuration ? $this->configuration : parent::getConfiguration($config, $container);
}
public function getName(){
return 'custom_notifo';
}
< /code>
Project structure
config
services.yaml
src
DependencyInjection
Configuration.php
WebantNotificationBundle.php
WebantNotificationExtension.php
Model
Mail.php
NotificationObject.php
NotifUser.php
Sms.php
SmsNotificationObject.php
Topic.php
TopicObject.php
Service
MobilePushService.php
NotifService.php
RequestService.php
TopicService.php
UserService.php
< /code>
I tried this command with namespace of my bundle: bin/console debug:container NotificationBundle
No services found that match "NotificationBundle".
Подробнее здесь: https://stackoverflow.com/questions/797 ... gcontainer
Custom Bundle Not Services не найдено в отладке: контейнер ⇐ Php
Кемеровские программисты php общаются здесь
-
Anonymous
1754935393
Anonymous
Мне нужно добавить новые функции в пользовательский пакет Symfony, который мой коллега ранее разработал. Чтобы работать с этим пакетом, я установил его в Symfony Base_App через композитор. Во время установки была ошибка, и в одном из файлов использовалось неправильное пространство имен. Вот пример того, как сейчас установлен пакет: < /p>
return [
// Custom\NotificationBundle\NotificationBundle::class => ['all' => true],
Custom\NotificationBundle\DependencyInjection\CustomNotificationBundle::class => ['all' => true],
];
< /code>
Во время работы с этим пакетом я сталкиваюсь с ошибкой: < /p>
Определение для "custom.notifo.service" не имеет класса. Если вы собираетесь динамически ввести эту службу во время выполнения, отметьте ее как Synthetic = true. Если это абстрактное определение, используемое исключительно по определениям детей, добавьте Abstract = true, в противном случае укажите класс, чтобы избавиться от этой ошибки.
Ошибка отображается, когда я пытаюсь запустить [b] bin/console config: summ notifo [/b]. />
services:
custom.notifo.service:
class: Custom\NotificationBundle\Service\NotifoService
arguments:
- '%custom.notifo.host%'
- '%custom.notifo.appid%'
- '%custom.notifo.apikey%'
- '@custom.notifo.requests_service'
- '%custom.notifo.sms.api_id%'
- '%custom.notifo.sms.sender_id%'
- '@logger'
public: true
autoconfigure: false
< /code>
bundle также имеет тесты и сервисы. Yaml выглядит так же: < /p>
services:
_defaults:
autowire: true
autoconfigure: true
custom.notifo.service:
class: Custom\NotificationBundle\Service\NotifoService
arguments: [ '%host%', '%appId%', '%apiKey%' , '@custom.notifo.requests_service', '%apiId%', '%senderId%', '@logger' ]
public: true
< /code>
Конфигурация выглядит так: < /p>
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('custom_notifo');
$treeBuilder->getRootNode()
->children()
->arrayNode('notifo')
->children()
->scalarNode('appid')
->defaultValue('custom')->end()
->scalarNode('apikey')
->defaultValue('custom')->end()
->scalarNode('host')
->defaultValue('custom')->end()
->arrayNode('sms')
->children()
->scalarNode('api_id')->isRequired()->cannotBeEmpty()->end()
->scalarNode('sender_id')->isRequired()->cannotBeEmpty()->end()
->end()
->end()
->end();
return $treeBuilder;
}
public function getName(){
return 'custom_notifo';
}
}
< /code>
Пакет выглядит следующим образом: < /p>
namespace Custom\NotificationBundle\DependencyInjection;
class CustomNotificationBundle extends Bundle
{
protected string $extensionAlias = 'custom_notifo';
public function build(ContainerBuilder $container): void
{
parent::build($container);
$extension = new CustomNotificationExtension();
$container->registerExtension($extension);
}
}
< /code>
У меня также есть этот класс < /p>
namespace Custom\NotificationBundle;
class NotificationBundle extends Bundle
{
}
< /code>
Я никогда раньше не работал с написанием пакета, поэтому я не знаю, что делать. Коллега сказал, что пакет работает, существует функция для отправки электронных писем через Notifo. < /P>
NotifoService: < /p>
namespace Webant\NotificationBundle\Service;
class NotifoService
{
private $eventsUrl;
private $usersUrl;
private string $smsApiId;
private string $smsSenderId;
private LoggerInterface $logger;
public function __construct(
private string $host,
private string $appId,
private string $apiKey,
private RequestsService $requests,
string $smsApiId,
string $smsSenderId,
LoggerInterface $logger
) {
$this->eventsUrl = 'https://'.$this->host .'/api/apps/'. $this->appId. '/events';
$this->usersUrl = 'https://' . $this->host . '/api/apps/' . $this->appId . '/users';
$this->smsApiId = $smsApiId;
$this->smsSenderId = $smsSenderId;
$this->logger = $logger;
}
public function sendNotification(Mail $mail): int{
$this->checkValidateNotification($mail);
if (!array_key_exists('templateName', get_object_vars($mail)) || $mail->templateName === ''){
throw new BadRequestException('Темплейт не может быть пустым', 400);
}
$notifoBody = new NotificationObject($mail);
$data = $notifoBody->requests;
return $this->notifoPostRequest($data, $this->eventsUrl);
}
public function notifoPostRequest(array $data, string $url): int{
$httpClient = HttpClient::create();
$options = $this->requests->makeOptions($this->host, $this->apiKey, $data);
$response = $httpClient->request(
Request::METHOD_POST,
$url,
$options
);
return $response->getStatusCode();
}
}
< /code>
namespace Custom\NotificationBundle\DependencyInjection;
class CustomNotificationExtension extends Extension
{
private $configuration;
public function load(array $configs, ContainerBuilder $container): void
{
$this->configuration = new Configuration();
$config = $this->processConfiguration($this->configuration, $configs);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('services.yaml');
$container->setParameter('custom.notifo.appid', $config['notifo']['appid']);
$container->setParameter('custom.notifo.apikey', $config['notifo']['apikey']);
$container->setParameter('custom.notifo.host', $config['notifo']['host']);
$container->setParameter('custom.notifo.sms.api_id', $config['notifo']['sms']['api_id']);
$container->setParameter('custom.notifo.sms.sender_id', $config['notifo']['sms']['sender_id']);
$container->register('custom.notifo.service')
->addArgument($config['notifo']['host'])
->addArgument($config['notifo']['appid'])
->addArgument($config['notifo']['apikey'])
->addArgument($config['notifo']['sms']['api_id'])
->addArgument($config['notifo']['sms']['sender_id']);
$container->register('custom.notifo.user_service')
->addArgument($config['notifo']['host'])
->addArgument($config['notifo']['appid']);
$container->register('custom.notifo.topic_service')
->addArgument($config['notifo']['host'])
->addArgument($config['notifo']['appid']);
$container->register('custom.notifo.mobile_push_service')
->addArgument($config['notifo']['host'])
->addArgument($config['notifo']['appid']);
}
public function setConfiguration(Configuration $configuration)
{
$this->configuration = $configuration;
}
public function getAlias(): string
{
return 'custom_notifo';
}
public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface
{
return $this->configuration ? $this->configuration : parent::getConfiguration($config, $container);
}
public function getName(){
return 'custom_notifo';
}
< /code>
Project structure
config
services.yaml
src
DependencyInjection
Configuration.php
WebantNotificationBundle.php
WebantNotificationExtension.php
Model
Mail.php
NotificationObject.php
NotifUser.php
Sms.php
SmsNotificationObject.php
Topic.php
TopicObject.php
Service
MobilePushService.php
NotifService.php
RequestService.php
TopicService.php
UserService.php
< /code>
I tried this command with namespace of my bundle: [b]bin/console debug:container NotificationBundle[/b]
No services found that match "NotificationBundle".
Подробнее здесь: [url]https://stackoverflow.com/questions/79726919/custom-bundle-no-services-found-in-debugcontainer[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия