Exemplo n.º 1
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());
 }
Exemplo n.º 2
0
 public function testBinaryIp()
 {
     $binaryIp = inet_pton('127.0.0.1');
     $paste = new Paste();
     $paste->setIp('127.0.0.1');
     $this->assertEquals($binaryIp, $paste->getBinaryIp());
     $paste = null;
     $paste = new Paste();
     $paste->setBinaryIp($binaryIp);
     $this->assertEquals('127.0.0.1', $paste->getIp());
 }
Exemplo n.º 3
0
    return new Response($paste->getContent(), 200, array('Cache-Control' => 's-maxage=' . $app['pastebin.cache.maxage'], 'Content-Disposition' => sprintf('attachment; filename="%s"', $filename)));
})->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;
});