Ejemplo n.º 1
0
 public function get($id)
 {
     $sql = "SELECT p.id, c.content, p.filename, p.token, datetime(p.timestamp, 'unixepoch') AS timestamp, p.ip, p.highlight " . "FROM pastes p, paste_content c " . "WHERE p.content_id = c.id AND p.token = :token";
     $this->logger->addDebug($sql);
     $stmt = $this->db->prepare($sql);
     $stmt->bindValue(':token', $id);
     $stmt->execute();
     $result = $stmt->fetch();
     // The statement failed to execute.
     if (false === $stmt->execute()) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException('SQL statement failed to execute.');
         // @codeCoverageIgnoreEnd
     }
     // There are no results.
     if (false === ($result = $stmt->fetch())) {
         return false;
     }
     // Assemble a paste model.
     $paste = new Paste();
     $paste->setId($result['id']);
     $paste->setContent($result['content']);
     $paste->setTimestamp(new \DateTime($result['timestamp']));
     $paste->setToken($result['token']);
     $paste->setFilename($result['filename']);
     $paste->setBinaryIp($result['ip']);
     $paste->setHighlight($result['highlight']);
     return $paste;
 }
Ejemplo n.º 2
0
 public function testGetLatest()
 {
     $paste = new Entity\Paste();
     $paste->setContent('This is a test.');
     $paste->setTimestamp(new \DateTime());
     $paste->setFilename('test.txt');
     $paste->setIp('127.0.0.1');
     $storage = $this->app['storage'];
     $id = $storage->save($paste);
     $this->assertEquals($id, $storage->getLatest());
 }
Ejemplo n.º 3
0
 public function testTabsToSpaces()
 {
     $paste = new Paste();
     $paste->setContent("Hello :)\tHello :)");
     $this->assertEquals("Hello :)\tHello :)", $paste->getContent());
     $paste = null;
     $paste = new Paste();
     $paste->setContent("Hello :)\tHello :)");
     $paste->setConvertTabs(true);
     $this->assertEquals("Hello :)    Hello :)", $paste->getContent());
     $paste = null;
     $paste = new Paste();
     $paste->setContent("Hello :)\tHello :)");
     $paste->setConvertTabs(false);
     $this->assertEquals("Hello :)\tHello :)", $paste->getContent());
 }
Ejemplo n.º 4
0
})->assert('id', '\\w+');
$app->get('/p/{id}/clone', function ($id) use($app) {
    $paste = $app['storage']->get($id);
    $form = $app['form.factory']->createBuilder(new Form\Paste(), $paste);
    $form = $form->getForm();
    $view = $app['twig']->render('new.html', array('form' => $form->createView()));
    return $view;
})->assert('id', '\\w+');
$app->get('/latest', function () use($app) {
    $id = $app['storage']->getLatest();
    return new RedirectResponse('/p/' . $id);
});
$app->post('/api', function (Request $request) use($app) {
    $paste = new Entity\Paste();
    $paste->setIp($request->getClientIp());
    $paste->setContent($request->request->get('content'));
    $paste->setFilename($request->request->get('filename'));
    $paste->setHighlight($request->request->get('highlight'));
    $errors = $app['validator']->validate($paste);
    if (count($errors) > 0) {
        $json = json_encode(array('success' => false, 'message' => "Missing required parameters."));
        return new Response($json, 400, array('Content-Type' => 'application/json'));
    }
    $id = $app['storage']->save($paste);
    $url = $request->getSchemeAndHttpHost() . '/p/' . $id;
    $response = new Response();
    $response->setStatusCode(201);
    $response->headers->set('Location', $url);
    return $response;
});
$app->get('/about', function () use($app) {