<?php
use Psr\Container\ContainerInterface;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
class SomeService
{
public function __constructor(
private ContainerInterface $container,
) {
}
public static function getSubscribedServices(): array
{
return [
ServiceFirst::class => ServiceFirst::class,
ServiceSecond::class => ServiceSecond::class,
SomeCommonService::class => SomeCommonService::class,
];
}
public function methodFirst()
{
$this->container[SomeCommonService::class]->doSomethingCommon();
$this->container[ServiceFirst::class]->doSomethingFirst();
return $this->commonMethod();
}
public function methodSecond()
{
$this->container[SomeCommonService::class]->doSomethingCommon();
$this->container[ServiceSecond::class]->doSomethingSecond();
return $this->commonMethod();
}
private function commonMethod(): string
{
// some code
return 'some string';
}
}
#!/bin/sh
# Создание временной директории
cd "$(mktemp --directory)";
# Клонирование репозитория во временную директорию
git clone https://github.com/symfony/demo .;
# Извлечение ветки для релиза
git checkout master;
# Установка зависимостей фронтенда
npm install
# Сборка фронтенда
node_modules/.bin/encore production
# Загрузка кода из временной директории на сервер при помощи rsync
# Остальные действия производятся уже на сервере
$ bin/console debug:config
$ bin/console debug:config gesdinet_jwt_refresh_token
public function api(EntityManagerInterface $entityManager): Response
{
$posts = $entityManager->createQuery('SELECT p FROM App\Entity\Post p')->getArrayResult();
return new JsonResponse($posts);
}
{% extends 'base.html.twig' %}
{% block body %}
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" href="#general-tab" data-toggle="tab" role="tab" aria-selected="true">
General
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#security-tab" data-toggle="tab" role="tab" aria-selected="false">
Security
</a>
</li>
</ul>
<div class="tab-content">
{{ form_start(form) }}
{{ form_errors(form) }}
<div class="tab-pane active show" id="general-tab" role="tabpanel" aria-labelledby="general-tab">
{{ form_row(form.field1) }}
{{ form_row(form.field2) }}
</div>
<div class="tab-pane" id="security-tab" role="tabpanel" aria-labelledby="security-tab">
{{ form_row(form.field3) }}
{{ form_row(form.field4) }}
</div>
<button type="submit">Submit</button>
{{ form_end(form) }}
</div>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script charset="utf-8">
$(function() {
$('a[data-toggle="tab"]').on('show.bs.tab', function(e) {
localStorage.setItem('activeTab', $(e.target).attr('href'));
});
var activeTab = localStorage.getItem('activeTab');
if (activeTab) {
$('.nav-tabs a[href="' + activeTab + '"]').tab('show');
}
});
</script>
{% endblock javascripts %}
{% block stylesheets %}
{{ parent() }}
<style type="text/css" media="screen">
.tab-pane:not(.show) {
display: none;
}
.tab-pane.show {
display: block;
}
</style>
{% endblock %}
SELECT MAX(employee.salary)
FROM AppBundle:Employee employee
JOIN employee.department department
WHERE department.id = :id
SELECT MAX(employee.salary)
FROM AppBundle:Employee employee
WHERE IDENTITY(employee.department) = :id
$client = self::createClient();
$client->setServerParameter('HTTP_HOST', 'symfony-test');
<?php
namespace App\Entity;
/**
* @Entity
*/
class User
{
const DEFAULT_ROLE = 'user';
/**
* @Column(type="string", options={"default": User::DEFAULT_ROLE})
*
* @var string
*/
private $role = self::DEFAULT_ROLE;
}
Перепробывал несколько бандлов - все ругаются на зависимости от симфы.
$repository
->createQueryBuilder('l')
->orderBy('l.addressCity', 'ASC')
->groupBy('l.addressCity');
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/blog")
*/
class BlogController extends AbstractController
{
/**
* @Route("/", methods="OPTIONS")
*/
public function options(Request $request): Response
{
$response = new Response();
$response->headers->set('Access-Control-Allow-Methods', 'OPTIONS, GET');
return $response;
}
/**
* @Route("/", methods="GET", name="blog_index")
*/
public function index(Request $request): Response
{
return $this->json([
'message' => 'hello',
]);
}
}
"autoload": {
"psr-4": {
"App\\": "src/",
"AcmeBundle\\": "bundles/AcmeBundle/"
},
}
<?php
namespace AcmeBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AcmeBundle extends Bundle
{
}
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
AcmeBundle\AcmeBundle::class => ['all' => true],
];
$ composer create-project symfony/skeleton
$fileLocator = new FileLocator([ __DIR__, __DIR__.'/../../app' ]);