$request
, а там из аттрибутов достать роут/контроллер doctrine.fixture.orm
This command looks for all services tagged withdoctrine.fixture.orm
. If you're using the default service configuration, any class that implementsORMFixtureInterface
(for example, those extending from Fixture) will automatically be registered with this tag.
@var GroupDto[]
чтоб сериалайзер понимал, что там типизированный массив.Cannot refresh token because user has changed.
$user->getRoles()
)$token = new UsernamePasswordToken($user, 'main', $user->getRoles());
class UserDTO
{
/**
* @var AutoDTO
* @Assert\Valid
*/
private $auto;
public function setAuto(AutoDTO $auto)
{
$this->auto = $auto;
return $this;
}
}
class AutoDTO
{
/**
* @var PriceDTO
* @Assert\Valid
*/
private $price;
public function setPrice(PriceDTO $price)
{
$this->price = $price;
return $this;
}
}
symfony/serializer
+ symfony/validator
+ symfony/security-csrf
$student = $this->serializer->deserialize(
$response->getContent(),
Student::class.'[]',
'json'
);
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) 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');
}
}
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();