Esempio n. 1
0
 public function putContent(ContentEntity $entity)
 {
     // This can potentially not work
     $folder = realpath($this->location);
     if (is_writable($folder) === false) {
         throw new \RuntimeException('Cannot find static templates location: ' . $this->location);
     }
     $filename = $folder . '/' . $entity->getName() . '.html.twig';
     $template = $this->twig->render('JadeITApplicationBundle:Content:static.html.twig.twig', array('content' => trim($entity->getContent())));
     // All code except the return can be replace by this one line once it's live
     // in Symfony
     //$this->fileSystem->dumpFile($filename, $template. 0644);
     if (is_writable(dirname($filename)) === false) {
         throw new \RuntimeException('Cannot write to static templates location: ' . dirname($filename));
     }
     $result = file_put_contents($filename, $template);
     return $template;
 }
 /**
  * Finds and displays a Content entity.
  *
  */
 public function showAction(Request $request, $id, $maxAge = null, $sharedAge = null, $private = null, $file = false)
 {
     // Read
     if ($file === false) {
         $em = $this->getDoctrine()->getManager();
         $entity = $em->getRepository('JadeITApplicationBundle:Content')->findOneByName($id);
     }
     // Check for a static file
     if (empty($entity)) {
         $entity = new Content();
         $entity->setName($id);
         $entity->setFormat($request->getRequestFormat());
     }
     if (empty($entity)) {
         throw $this->createNotFoundException('Unable to find Content entity.');
     }
     // Fire the Read Content Event
     $event = new ContentEvent($entity, $request);
     $dispatcher = $this->get('event_dispatcher');
     $dispatcher->dispatch('notes.events.content.read', $event);
     // Render
     if ($this->get('security.context')->isGranted('ROLE_ADMIN')) {
         $deleteForm = $this->createDeleteForm($entity->getId())->createView();
     } else {
         $deleteForm = false;
     }
     try {
         $response = $this->container->get('templating')->renderResponse($entity->getTemplate(), array('entity' => $entity, 'delete_form' => $deleteForm));
     } catch (\InvalidArgumentException $e) {
         throw $this->createNotFoundException('Could not find ' . $entity->getName(), $e);
     }
     if ($maxAge) {
         $response->setMaxAge($maxAge);
     }
     if ($sharedAge) {
         $response->setSharedMaxAge($sharedAge);
     }
     if ($private) {
         $response->setPrivate();
     } elseif ($private === false || null === $private && ($maxAge || $sharedAge)) {
         $response->setPublic($private);
     }
     return $response;
 }