public function onResponse(FilterResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $responseData = $event->getResponse()->getContent();
     $formatedJson = Json::indent($responseData);
     $newResponse = new Response($formatedJson);
     $event->setResponse($newResponse);
 }
 public function onResponse(FilterResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     $route = $request->attributes->get('_route');
     if (strpos($route, 'newscoop_gimme_') === false) {
         return;
     }
     if (APPLICATION_ENV === 'development' || APPLICATION_ENV === 'dev' || $request->query->get('pretty_json', false) == true) {
         $response = $event->getResponse();
         $responseData = $event->getResponse()->getContent();
         $response->setContent(Json::indent($responseData));
         $event->setResponse($response);
     }
 }
Exemplo n.º 3
0
 /**
  * Remove plugin from newscoop (composer+database+cleaning)
  *
  * @param  string          $pluginName
  * @param  OutputInterface $output
  * @param  boolean         $notify
  */
 public function removePlugin($pluginName, OutputInterface $output, $notify = true)
 {
     $this->installComposer();
     $this->prepareCacheDir();
     /*if (!$this->isInstalled($pluginName)) {
                 $output->writeln('<info>Plugin "'.$pluginName.'" is not installed yet</info>');
     
                 return;
             }*/
     $composerFile = $this->newsoopDir . 'composer.json';
     $composerDefinitions = json_decode(file_get_contents($composerFile), true);
     foreach ($composerDefinitions['require'] as $package => $version) {
         if ($package == $pluginName) {
             if ($notify) {
                 $process = new Process('cd ' . $this->newsoopDir . ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' application/console plugins:dispatch ' . $pluginName . ' remove');
                 $process->setTimeout(3600);
                 $process->run(function ($type, $buffer) use($output) {
                     if ('err' === $type) {
                         $output->write('<error>' . $buffer . '</error>');
                     } else {
                         $output->write('<info>' . $buffer . '</info>');
                     }
                 });
                 if (!$process->isSuccessful()) {
                     throw new \Exception("Error with dispatching remove event", 1);
                 }
             }
             $output->writeln('<info>Remove "' . $pluginName . '" from composer.json file</info>');
             unset($composerDefinitions['require'][$package]);
             file_put_contents($composerFile, \Newscoop\Gimme\Json::indent(json_encode($composerDefinitions)));
             $process = new Process('cd ' . $this->newsoopDir . ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' composer.phar update ' . $this->dev . ' ' . $pluginName);
             $process->setTimeout(3600);
             $process->run(function ($type, $buffer) use($output) {
                 if ('err' === $type) {
                     $output->write('<error>' . $buffer . '</error>');
                 } else {
                     $output->write('<info>' . $buffer . '</info>');
                 }
             });
             if (!$process->isSuccessful()) {
                 throw new \Exception("Error with removing plugin", 1);
             }
         }
     }
     $cachedPluginMeta = $this->newsoopDir . '/plugins/cache/uninstall_' . str_replace('/', '-', $pluginName) . '_package.json';
     if (file_exists($cachedPluginMeta)) {
         $pluginMeta = json_decode(file_get_contents($cachedPluginMeta), true);
         $this->em->getRepository('Newscoop\\Entity\\Plugin')->removePlugin($pluginName);
         // clear cache files
         $filesystem = new Filesystem();
         $filesystem->remove($cachedPluginMeta);
         $filesystem->remove($this->pluginsDir . '/' . $pluginMeta['targetDir'] . '/');
     }
     $this->saveAvaiablePluginsToCacheFile();
     $this->clearCache($output);
     $output->writeln('<info>Plugin ' . $pluginName . ' is removed!</info>');
 }