public function indexAction() { $list = []; $em = $this->get('doctrine.orm.entity_manager'); $sources = $em->getRepository('MDSSiteBundle:Source')->findAll(); foreach ($sources as $source) { try { MPD::connect($source->getMpdpassword(), $source->getMpdhost(), $source->getMpdport()); $ping = MPD::send("ping"); if ($ping['status'] == 'OK') { $connect = true; } else { $connect = false; } MPD::disconnect(); } catch (MPDConnectionFailedException $e) { $connect = false; } catch (Exception $e) { $connect = false; } if ($connect) { $list[] = $source; } } return $this->render('MDSSiteBundle:Page:page.default.html.twig', array('list' => $list)); }
protected function getResult() { $sourceId = $this->request->request->get('sourceid'); if (!$sourceId) { return 'Пожалуйста проверте sourceId'; } try { $source = $this->em->getRepository('MDSSiteBundle:Source')->find($sourceId); } catch (EntityNotFoundException $e) { return $e; } try { MPD::connect($source->getMpdpassword(), $source->getMpdhost(), $source->getMpdport()); } catch (MPDConnectionFailedException $e) { return "No connection"; } $currentSong = MPD::currentSong(); return 'Имя трека'; }