Skip to content

Commit

Permalink
Intial work on the Dustbin Pastebin
Browse files Browse the repository at this point in the history
  • Loading branch information
meonkeys committed Apr 1, 2012
1 parent 347fe40 commit 8351248
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/AppKernel.php
Expand Up @@ -17,6 +17,7 @@ public function registerBundles()
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new TwoBulb\PasteBundle\TwoBulbPasteBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
Expand Down
2 changes: 1 addition & 1 deletion app/config/config_dev.yml
Expand Up @@ -14,7 +14,7 @@ monolog:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
level: info
firephp:
type: firephp
level: info
Expand Down
5 changes: 5 additions & 0 deletions app/config/routing.yml
Expand Up @@ -2,3 +2,8 @@
#_internal:
# resource: "@FrameworkBundle/Resources/config/routing/internal.xml"
# prefix: /_internal

paste:
resource: "@TwoBulbPasteBundle/Controller"
type: annotation
prefix: /
62 changes: 62 additions & 0 deletions src/TwoBulb/PasteBundle/Controller/PasteController.php
@@ -0,0 +1,62 @@
<?php

namespace TwoBulb\PasteBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use TwoBulb\PasteBundle\Service\Paste;

/**
* @Route("/p");
*/
class PasteController extends Controller {

/**
* @return \TwoBulb\PasteBundle\Service\PasteService
*/
private function getPasteService() {
return $this->get('twobulb_paste_service');
}

/**
* @Route("/get/{id}")
* @Template()
*/
public function getAction($id) {
$pasteService = $this->getPasteService();
return array('paste' => $pasteService->fetchOne($id));
}

/**
* @Route("/new")
* @Template()
*/
public function newAction(Request $request) {
$pasteService = $this->getPasteService();
$paste = new Paste();
$form = $this->createFormBuilder($paste)
->add('content', 'textarea', array('label' => ' ', 'attr' => array('cols' => 80, 'rows' => 24)))
->getForm();
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);

if ($form->isValid()) {
$paste = $pasteService->store($paste);

return $this->redirect($this->generateUrl('twobulb_paste_paste_get', array('id' => $paste->getId())));
}
}
return array('form' => $form->createView());
}

/**
* @Route("/list")
* @Template()
*/
public function listAction() {
return array();
}

}
@@ -0,0 +1,17 @@
<?php

namespace TwoBulb\PasteBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;

class TwoBulbPasteExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
4 changes: 4 additions & 0 deletions src/TwoBulb/PasteBundle/Resources/config/services.yml
@@ -0,0 +1,4 @@
services:
twobulb_paste_service:
class: TwoBulb\PasteBundle\Service\InMemoryPasteService
arguments: ["@logger"]
20 changes: 20 additions & 0 deletions src/TwoBulb/PasteBundle/Resources/public/css/main.css
@@ -0,0 +1,20 @@
/*
TODO customize this sample style
Syntax recommendation http://www.w3.org/TR/REC-CSS2/
*/

maincontent {
font-size: 14px;
font-family: "Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
}

h1, h2, h3
{
font-family: Georgia, "Times New Roman", Times, serif;
}

.footer
{
font-size: small;
}

7 changes: 7 additions & 0 deletions src/TwoBulb/PasteBundle/Resources/views/Paste/get.html.twig
@@ -0,0 +1,7 @@
{% extends "TwoBulbPasteBundle::layout.html.twig" %}

{% block title %}View Paste {{ paste.id }} - Dustbin{% endblock %}

{% block content %}
<pre>{{ paste.content }}</pre>
{% endblock %}
7 changes: 7 additions & 0 deletions src/TwoBulb/PasteBundle/Resources/views/Paste/list.html.twig
@@ -0,0 +1,7 @@
{% extends "TwoBulbPasteBundle::layout.html.twig" %}

{% block title %}List Pastes - Dustbin{% endblock %}

{% block content %}
<pre>(list will go here...)</pre>
{% endblock %}
12 changes: 12 additions & 0 deletions src/TwoBulb/PasteBundle/Resources/views/Paste/new.html.twig
@@ -0,0 +1,12 @@
{% extends "TwoBulbPasteBundle::layout.html.twig" %}

{% block title %}New Paste - Dustbin{% endblock %}

{% block content %}
<div id="newPasteForm">
<form action="{{ path('twobulb_paste_paste_new') }}" method="post" {{ form_enctype(form) }}>
{{ form_widget(form) }}
<input type="submit" />
</form>
</div>
{% endblock %}
25 changes: 25 additions & 0 deletions src/TwoBulb/PasteBundle/Resources/views/layout.html.twig
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="{{ asset('bundles/twobulbpaste/css/main.css') }}" type="text/css" media="all" />
<title>{% block title %}Dustbin Pastebin{% endblock %}</title>
<link rel="shortcut icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>
{% if app.session.flash('notice') %}
<div class="flash-message">
<em>Notice</em>: {{ app.session.flash('notice') }}
</div>
{% endif %}

<div class="maincontent">
{% block content %}
{% endblock %}
</div>
<hr/>
<div class="footer">
<a href="{{ path('twobulb_paste_paste_new') }}">New paste</a> | <a href="{{ path('twobulb_paste_paste_list') }}">List pastes</a>
</div>
</body>
</html>
46 changes: 46 additions & 0 deletions src/TwoBulb/PasteBundle/Service/InMemoryPasteService.php
@@ -0,0 +1,46 @@
<?php

namespace TwoBulb\PasteBundle\Service;

class InMemoryPasteService implements PasteService {

private $log;
private $db;

public function __construct($log) {
$log->info("InMemoryPasteService::__construct()");
$this->db = array();
}

/**
* @return array
*/
public function fetchMany($limit, $offset) {
$p = new Paste();
return $p->setId(1)->setContent("blah");
}

/**
* @param string $id
* @return Paste
*/
public function fetchOne($id) {
return $this->db[$id];
}

private function generateId() {
return 1;
}

/**
* @param Paste $paste
* @return Paste just-stored object
*/
public function store(Paste $paste) {
$id = $this->generateId();
$paste->setId($id);
$this->db[$paste->getId()] = $paste;
return $paste;
}

}
17 changes: 17 additions & 0 deletions src/TwoBulb/PasteBundle/Service/MongoDBPasteService.php
@@ -0,0 +1,17 @@
<?php

namespace TwoBulb\PasteBundle\Service;

class MongoDBStorage implements PasteService {
public function fetchMany($limit, $offset) {

}

public function fetchOne($id) {

}

public function store(Paste $paste) {

}
}
28 changes: 28 additions & 0 deletions src/TwoBulb/PasteBundle/Service/Paste.php
@@ -0,0 +1,28 @@
<?php

namespace TwoBulb\PasteBundle\Service;

class Paste {

private $id;
private $content;

public function getId() {
return $this->id;
}

public function setId($id) {
$this->id = $id;
return $this;
}

public function getContent() {
return $this->content;
}

public function setContent($content) {
$this->content = $content;
return $this;
}

}
12 changes: 12 additions & 0 deletions src/TwoBulb/PasteBundle/Service/PasteService.php
@@ -0,0 +1,12 @@
<?php

namespace TwoBulb\PasteBundle\Service;

interface PasteService {

function fetchOne($id);

function fetchMany($limit, $offset);

function store(Paste $paste);
}
9 changes: 9 additions & 0 deletions src/TwoBulb/PasteBundle/TwoBulbPasteBundle.php
@@ -0,0 +1,9 @@
<?php

namespace TwoBulb\PasteBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class TwoBulbPasteBundle extends Bundle
{
}

0 comments on commit 8351248

Please sign in to comment.