public function parse($manager) { $log_file = 'access_test.log'; $pattern = '/^(?<client>\\S+) +(?<clientid>\\S+)' . '+(?<userid>\\S+) \\[(?<datetime>[^\\]]+)\\]' . ' "(?<method>[A-Z]+)(?<request>[^"]+)?HTTP\\/[0-9.]+"' . ' (?<status>[0-9]{3}) (?<size>[0-9]+)/'; $file_handle = fopen($log_file, "r"); $line = fgets($file_handle); preg_match_all($pattern, $line, $matches); while (!feof($file_handle)) { $line = fgets($file_handle); //new entry instance $entry = new Entry(); //look for pattern in line preg_match_all($pattern, $line, $matches); //populate entry $entry->setClient(@$matches['client'][0]); $entry->setClientid(@$matches['clientid'][0]); $entry->setUserid(@$matches['userid'][0]); $str = new \DateTime(@$matches['datetime'][0]); $entry->setTimed($str); $entry->setMethod(@$matches['method'][0]); $entry->setRequest(@$matches['request'][0]); $entry->setStatusCode(@$matches['status'][0]); $entry->setSize(@$matches['size'][0]); if (@$matches['client'][0] != null) { //persist entry to DB $manager->persist($entry); $manager->flush(); } else { break; fclose($file_handle); } } return 'log file parsed successfully!'; }
/** * @param EntryExcel $entryExcel * @return Entry */ public function createEntryEntity(EntryExcel $entryExcel) { $entry = new Entry(); $entry->setConcept($entryExcel->getConcept()); $entry->setDate($entryExcel->getDate()); $entry->setValue($entryExcel->getValue()); return $entry; }
/** * @Route("/app/entries/{project_id}", name="entries") * @ParamConverter("project", class="AppBundle:Project", options={"id" = "project_id"}) */ public function entriesAction(Request $request, Project $project) { $em = $this->getDoctrine()->getManager(); $from = $request->get('from', strtotime('first day of this month')); $to = $request->get('to', strtotime('last day of this month')); $entry = new Entry(); $entry->setProject($project); $entry->setUser($this->getUser()); $entry->setIssuedAt(new \DateTime()); $entry->setCreatedAt(new \DateTime()); $form = $this->createForm(EntryType::class, $entry, array('action' => $this->generateUrl('entries', array('project_id' => $project->getId())), 'method' => 'POST')); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { // ... perform some action, such as saving the task to the database $em->persist($entry); $em->flush(); return $this->redirectToRoute('entries', array('project_id' => $project->getId())); } $query = $em->createQuery('SELECT e, u FROM AppBundle:Entry e JOIN e.user u WHERE e.project = :project ORDER BY e.issuedAt DESC, e.createdAt DESC')->setParameter('project', $project); $entries = $query->getResult(); // replace this example code with whatever you need return $this->render('AppBundle:Default:entries.html.twig', ['project' => $project, 'entries' => $entries, 'form' => $form->createView()]); }
/** * Creates a form to delete a Entry entity. * * @param Entry $entry The Entry entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Entry $entry) { return $this->createFormBuilder()->setAction($this->generateUrl('app_entry_delete', array('id' => $entry->getId())))->setMethod('DELETE')->getForm(); }
public function relatedEntitiesAction() { $category = new Entry(); $category->setName('Main Products'); $product = new Movie(); $product->setName('Foo'); $product->setPrice(19.99); $product->setDescription('Lorem ipsum dolor'); // relate this product to the category $product->setCategory($category); $em = $this->getDoctrine()->getManager(); $em->persist($category); $em->persist($product); $em->flush(); return new Response('Created product id: ' . $product->getId() . ' and category id: ' . $category->getId()); //fetchin related $product = $this->getDoctrine()->getRepository('AppBundle:Product')->find($id); $categoryName = $product->getCategory()->getName(); }