App\handler\action\Handler:
arguments: !service_locator
type1: '@App\handler\create\Handler'
type2: '@App\handler\upload\Handler'
Services should not use autowiring or autoconfiguration. Instead, all services should be defined explicitly.
The reason is that bundles shouldn't rely on features such as service autowiring or autoconfiguration to not impose an overhead when compiling application services.
Y-m-d
(1), внутри формы используется объект DateTime
(2), а для вывода пользователю используется локализованная строка либо набор селектов (3). ModelTransformer
чтобы преобразовать строку (1) в объект (2) и использовать ViewTransformer
чтобы в зависимости от опций, переданных в форму, преобразовать объект (2) в строку или селекты (3) $response = $client->request(
'POST',
'http://'.$_SERVER['SERVER_NAME'].$this->generateUrl('like_product_controller'), [
GuzzleHttp\RequestOptions::FORM_PARAMS => [
'hash' => $request->request->get('hash'),
],
]
);
abstract class Controller extends AbstractController
{
public static function getSubscribedServices()
{
return array_merge(parent::getSubscribedServices(), [
'setting' => Setting::class,
]);
}
protected function getSetting(): Setting
{
return $this->get('setting');
}
}
PATH_SEPARATOR
(тот который в переменной окружения PATH
) и DIRECTORY_SEPARATOR
EntityManager
, а не создавать их самим.UserRepository
прописать в маппинге сущности@ORM\Entity(repositoryClass="UserRepository")
IS_AUTHENTICATED_FULLY
надо заменить на IS_AUTHENTICATED_REMEMBERED
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: ROLE_ADMIN }
- { path: ^/system/*, role: ROLE_ADMIN }
- { path: ^/*, role: IS_AUTHENTICATED_REMEMBERED }
interface ExecutorInterface
{
public function exec(): string;
}
class ConcreteImplementationA implements ExecutorInterface
{
public function exec(): string
{
return 'A';
}
}
class ConcreteImplementationB implements ExecutorInterface
{
public function exec(): string
{
return 'B';
}
}
class VariantExecutor
{
public function __construct(private ServiceLocator $locator)
{
}
public function exec(string $variant): string
{
return $this->locator->get($variant)->exec();
}
}
class Controller
{
public function call(VariantExecutor $executor, string $variant): Response
{
return new Response($executor->exec($variant));
}
}
#services.yaml
app.executor.locator:
class: Symfony\Component\DependencyInjection\ServiceLocator
arguments:
-
a: App\ConcreteImplementationA
b: App\ConcreteImplementationB
tags:
- { name: container.service_locator }
/**
* @param bool $resolveEnvPlaceholders Whether %env()% parameters should be resolved using the current
* env vars or be replaced by uniquely identifiable placeholders.
* Set to "true" when you want to use the current ContainerBuilder
* directly, keep to "false" when the container is dumped instead.
*/
public function compile(bool $resolveEnvPlaceholders = false)
$container->compile(true);
$ids = [1, 2, 3, 4];
$this->getEntityManager()->getConnection()
->executeStatement('UPDATE some_table SET some_field = ? WHERE id IN (?)', [
'value',
$ids,
], [
1 => Connection::PARAM_INT_ARRAY,
]);
$builder = $this->getEntityManager()->getConnection()->createQueryBuilder();
$builder
->update('some_table')
->set('some_field', ':value')
->where($builder->expr()->in('id', ':ids'))
->setParameter('value', 'value')
->setParameter('ids', $ids, Connection::PARAM_INT_ARRAY)
;
$builder->execute()
$this->getEntityManager()
->createQuery('UPDATE App\Entity\SomeEntity se SET se.someValue = :value WHERE se.id IN (:ids)')
->execute(new ArrayCollection([
new Parameter('value', 'value'),
new Parameter('ids', $ids),
]))
);
$builder = $this->createQueryBuilder('se');
$builder
->update()
->set('se.someValue', ':value')
->where($builder->expr()->in('uu.id', ':ids'))
->setParameter('value', 'value')
->setParameter('ids', $ids)
;
$builder->getQuery()->execute();
\App\Entity\Group::__toString
, либо добавьте опцию choice_label->add('group', null, [
'choice_label' => 'getName', // Метод, который вернет название группы
])
$post = new Post();
// Заполняем поля, которые присутствуют в форме
$post->setPublishedAt(new \DateTime());
$post->setTitle('New title');
// Если объекты не используются, то заполнять надо массив
// $post = [];
// $post['publishedAt'] = new \DateTime();
// $post['title'] = 'New title';
$form = $this->createForm(PostType::class, $post);
// ...
return $this->render('post.html.twig', [
'form' => $form->createView(),
])
$builder->get('publishedAt')->setData(new \DateTime());
$builder->get('title')->setData('New title');
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$data = $event->getData();
if ($data !== null) {
return;
}
$event->setData([
'title' => 'New title',
'publishedAt' => new \DateTime(),
]);
});
# servces.yaml
services:
Monolog\Handler\TelegramBotHandler:
arguments:
- '%env(TELEGRAM_BOT_KEY)%'
- '%env(TELEGRAM_CHANNEL)%'
# monolog.yaml
monolog:
handlers:
message:
type: fingers_crossed
action_level: error
excluded_http_codes: [ 400, 401, 403, 404 ]
buffer_size: 50
handler: deduplicated
deduplicated:
type: deduplication
handler: telegram
telegram: # Важна только эта часть
type: service
id: Monolog\Handler\TelegramBotHandler
level: debug