Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/TwoBulb/PasteBundle/DependencyInjection/TwoBulbPasteExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
services: | ||
twobulb_paste_service: | ||
class: TwoBulb\PasteBundle\Service\InMemoryPasteService | ||
arguments: ["@logger"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends "TwoBulbPasteBundle::layout.html.twig" %} | ||
|
||
{% block title %}View Paste {{ paste.id }} - Dustbin{% endblock %} | ||
|
||
{% block content %} | ||
<pre>{{ paste.content }}</pre> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
12
src/TwoBulb/PasteBundle/Resources/views/Paste/new.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace TwoBulb\PasteBundle\Service; | ||
|
||
interface PasteService { | ||
|
||
function fetchOne($id); | ||
|
||
function fetchMany($limit, $offset); | ||
|
||
function store(Paste $paste); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace TwoBulb\PasteBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class TwoBulbPasteBundle extends Bundle | ||
{ | ||
} |