ozo2003 /
HelperBundle
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Sludio\HelperBundle\Lexik\Controller; |
||
| 4 | |||
| 5 | use Doctrine\DBAL\DBALException; |
||
| 6 | use Lexik\Bundle\TranslationBundle\Entity\TransUnit; |
||
| 7 | use Lexik\Bundle\TranslationBundle\Manager\TranslationInterface; |
||
| 8 | use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; |
||
| 9 | use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
||
| 10 | use Symfony\Component\HttpFoundation\StreamedResponse; |
||
| 11 | use Symfony\Component\Yaml\Dumper; |
||
| 12 | |||
| 13 | trait NonActionTrait |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Execute a batch download |
||
| 17 | * |
||
| 18 | * @param ProxyQueryInterface $queryProxy |
||
| 19 | * |
||
| 20 | * @return StreamedResponse |
||
| 21 | * @internal param ProxyQueryInterface $query |
||
| 22 | * @throws \InvalidArgumentException |
||
| 23 | */ |
||
| 24 | public function batchActionDownload(ProxyQueryInterface $queryProxy) |
||
| 25 | { |
||
| 26 | $flashType = 'success'; |
||
| 27 | |||
| 28 | $dumper = new Dumper(); |
||
| 29 | $dumper->setIndentation(4); |
||
|
0 ignored issues
–
show
|
|||
| 30 | |||
| 31 | $response = new StreamedResponse(function() use ($queryProxy, &$flashType, $dumper) { |
||
| 32 | try { |
||
| 33 | /** |
||
| 34 | * @var TransUnit $transUnit |
||
| 35 | */ |
||
| 36 | $iterates = $queryProxy->getQuery()->iterate(); |
||
| 37 | /** @var $iterates array */ |
||
| 38 | foreach ($iterates as $pos => $object) { |
||
| 39 | /** @var $object array */ |
||
| 40 | foreach ($object as $transUnit) { |
||
| 41 | $chunkPrefix = $transUnit->getDomain().'__'.$transUnit->getKey().'__'.$transUnit->getId().'__'; |
||
| 42 | $chunk = []; |
||
| 43 | /** @var TranslationInterface $translation */ |
||
| 44 | foreach ($transUnit->getTranslations() as $translation) { |
||
| 45 | $chunk[$chunkPrefix.$translation->getLocale()] = $translation->getContent(); |
||
| 46 | } |
||
| 47 | echo $dumper->dump($chunk, 2); |
||
| 48 | flush(); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } catch (\PDOException $e) { |
||
| 52 | $flashType = 'error'; |
||
| 53 | flush(); |
||
| 54 | } catch (DBALException $e) { |
||
| 55 | $flashType = 'error'; |
||
| 56 | flush(); |
||
| 57 | } |
||
| 58 | }); |
||
| 59 | |||
| 60 | $this->addFlash('sonata_flash_'.$flashType, 'translations.flash_batch_download_'.$flashType); |
||
| 61 | |||
| 62 | $response->headers->set('Content-Type', 'text/x-yaml'); |
||
| 63 | $response->headers->set('Cache-Control', ''); |
||
| 64 | $response->headers->set('Transfer-Encoding', 'chunked'); |
||
| 65 | $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s')); |
||
| 66 | $contentDisposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'translations.yml'); |
||
| 67 | $response->headers->set('Content-Disposition', $contentDisposition); |
||
| 68 | |||
| 69 | return $response; |
||
| 70 | } |
||
| 71 | |||
| 72 | abstract protected function addFlash($type, $message); |
||
| 73 | |||
| 74 | public function __toString() |
||
| 75 | { |
||
| 76 | return 'sludio_helper.lexik.crud.controller'; |
||
| 77 | } |
||
| 78 | |||
| 79 | protected function getManagedLocales() |
||
| 80 | { |
||
| 81 | return $this->container->getParameter('lexik_translation.managed_locales'); |
||
| 82 | } |
||
| 83 | } |
||
| 84 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.