Many upgrade changes. Templating system refactored. Routing cleaned out. Many thingls simplified.

This commit is contained in:
Alexey Skobkin 2019-01-19 21:26:28 +03:00
parent 83ac9fda67
commit ba788e7746
16 changed files with 77 additions and 66 deletions

View File

@ -0,0 +1,6 @@
{% extends 'base.html.twig' %}
{% block content %}
{# This form recieves form_create object from current context #}
{% include 'Form/form_paste_create.html.twig' %}
{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends '::base.html.twig' %} {% extends 'base.html.twig' %}
{% block content %} {% block content %}
<div class="paste container-fluid"> <div class="paste container-fluid">
@ -66,7 +66,7 @@
</div> </div>
<div role="tabpanel" class="tab-pane" id="tab-paste-edit"> <div role="tabpanel" class="tab-pane" id="tab-paste-edit">
{# This form recieves form_create object from current context #} {# This form recieves form_create object from current context #}
{% include 'SkobkinCopyPasteBundle:Form:form_paste_create.html.twig' %} {% include 'Form/form_paste_create.html.twig' %}
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,4 +1,4 @@
{% extends '::layout.html.twig' -%} {% extends 'layout.html.twig' -%}
{%- block css -%} {%- block css -%}
{{- parent() -}} {{- parent() -}}
@ -20,7 +20,7 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="{{ path('copypaste_new') }}">{{ 'header_title' | trans }}</a> <a class="navbar-brand" href="{{ path('paste_new') }}">{{ 'header_title' | trans }}</a>
</div> </div>
<!-- Collect the nav links, forms, and other content for toggling --> <!-- Collect the nav links, forms, and other content for toggling -->
@ -28,7 +28,7 @@
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
{% block header_menu_left_items %} {% block header_menu_left_items %}
<li{% if app.request.attributes.get('_route') == 'copypaste_new' %} class="active"{% endif %}> <li{% if app.request.attributes.get('_route') == 'copypaste_new' %} class="active"{% endif %}>
<a href="{{ path('copypaste_new') }}"><span class="glyphicon glyphicon-plus-sign"></span> {{ 'header_menu_add' | trans }}</a> <a href="{{ path('paste_new') }}"><span class="glyphicon glyphicon-plus-sign"></span> {{ 'header_menu_add' | trans }}</a>
</li> </li>
<li> <li>
<a href="{#{{ path('about') }}#}"><span class="glyphicon glyphicon-info-sign"></span> {{ 'header_menu_about' | trans }}</a> <a href="{#{{ path('about') }}#}"><span class="glyphicon glyphicon-info-sign"></span> {{ 'header_menu_about' | trans }}</a>
@ -46,7 +46,7 @@
{%- endblock -%} {%- endblock -%}
{%- block sidebar -%} {%- block sidebar -%}
{{ render(controller('SkobkinCopyPasteBundle:Paste:sidebar')) }} {{ render(controller('Skobkin\\Bundle\\CopyPasteBundle\\Controller\\PasteController::sidebarAction')) }}
{%- endblock -%} {%- endblock -%}
{% block content %}{% endblock %} {% block content %}{% endblock %}

View File

@ -3,7 +3,7 @@
<div class="panel-heading">{{ 'sidebar_title' | trans() }}</div> <div class="panel-heading">{{ 'sidebar_title' | trans() }}</div>
<ul class="list-group"> <ul class="list-group">
{% for paste in pastes %} {% for paste in pastes %}
<a href="{{ path('copypaste_show_public', {'id': paste.id}) }}" class="list-group-item"> <a href="{{ path('paste_show_public', {'id': paste.id}) }}" class="list-group-item">
#{{ paste.id }}&nbsp;-&nbsp;{% if paste.author %}{{ paste.author }}{% else %}anonymous{% endif %} #{{ paste.id }}&nbsp;-&nbsp;{% if paste.author %}{{ paste.author }}{% else %}anonymous{% endif %}
</a> </a>
{% endfor %} {% endfor %}

View File

@ -13,17 +13,21 @@ framework:
form: ~ form: ~
csrf_protection: ~ csrf_protection: ~
validation: { enable_annotations: true } validation: { enable_annotations: true }
templating: #serializer: { enable_annotations: true }
engines: ['twig'] default_locale: '%locale%'
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~ trusted_hosts: ~
trusted_proxies: ~
session: session:
# handler_id set to null will use default session handler from php.ini # handler_id set to null will use default session handler from php.ini
handler_id: ~ handler_id: ~
fragments: ~ fragments: ~
http_method_override: true http_method_override: true
assets: ~
php_errors:
log: true
sensio_framework_extra:
router:
annotations: false
# Twig Configuration # Twig Configuration
twig: twig:
@ -31,7 +35,7 @@ twig:
strict_variables: "%kernel.debug%" strict_variables: "%kernel.debug%"
form_themes: form_themes:
- 'bootstrap_3_layout.html.twig' - 'bootstrap_3_layout.html.twig'
- 'SkobkinCopyPasteBundle:Form:fields.html.twig' - 'Form/fields.html.twig'
# Doctrine Configuration # Doctrine Configuration
doctrine: doctrine:

View File

@ -1,4 +1,21 @@
skobkin_copy_paste: paste_show_public:
resource: "@SkobkinCopyPasteBundle/Resources/config/routing.yml" path: /{id}
prefix: / defaults: { _controller: 'Skobkin\Bundle\CopyPasteBundle\Controller\PasteController::showAction', secret: null }
requirements:
id: \d+
paste_show_private:
path: /{id}/{secret}
defaults: { _controller: 'Skobkin\Bundle\CopyPasteBundle\Controller\PasteController::showAction' }
requirements:
id: \d+
secret: \w{16}
paste_new:
path: /
defaults: { _controller: 'Skobkin\Bundle\CopyPasteBundle\Controller\PasteController::newAction' }
paste_create:
path: /create
defaults: { _controller: 'Skobkin\Bundle\CopyPasteBundle\Controller\PasteController::createAction' }
methods: POST

View File

@ -4,6 +4,27 @@ parameters:
# parameter_name: value # parameter_name: value
services: services:
# service_name: # default configuration for services in *this* file
# class: AppBundle\Directory\ClassName _defaults:
# arguments: ["@another_service_name", "plain_value", "%parameter_name%"] # automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
Skobkin\Bundle\CopyPasteBundle\:
resource: '../../src/Skobkin/Bundle/CopyPasteBundle/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../../src/Skobkin/Bundle/CopyPasteBundle/{DataFixtures,DependencyInjection,Entity,Repository,Tests}'
# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
Skobkin\Bundle\CopyPasteBundle\Controller\:
resource: '../../src/Skobkin/Bundle/CopyPasteBundle/Controller'
public: true
tags: ['controller.service_arguments']

View File

@ -2,6 +2,7 @@
namespace Skobkin\Bundle\CopyPasteBundle\Controller; namespace Skobkin\Bundle\CopyPasteBundle\Controller;
use DT\Bundle\GeshiBundle\Highlighter\HighlighterInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -9,7 +10,6 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use \Symfony\Component\Form\Form; use \Symfony\Component\Form\Form;
use Skobkin\Bundle\CopyPasteBundle\Entity\Copypaste; use Skobkin\Bundle\CopyPasteBundle\Entity\Copypaste;
use Skobkin\Bundle\CopyPasteBundle\Form\CopypasteType; use Skobkin\Bundle\CopyPasteBundle\Form\CopypasteType;
use DT\Bundle\GeshiBundle\Highlighter\GeshiHighlighter;
use \GeSHi\GeSHi; use \GeSHi\GeSHi;
class PasteController extends Controller class PasteController extends Controller
@ -54,9 +54,9 @@ class PasteController extends Controller
$em->flush(); $em->flush();
if ($paste->isPrivate()) { if ($paste->isPrivate()) {
return $this->redirect($this->generateUrl('copypaste_show_private', ['id' => $paste->getId(), 'secret' => $paste->getSecret()])); return $this->redirect($this->generateUrl('paste_show_private', ['id' => $paste->getId(), 'secret' => $paste->getSecret()]));
} else { } else {
return $this->redirect($this->generateUrl('copypaste_show_public', ['id' => $paste->getId()])); return $this->redirect($this->generateUrl('paste_show_public', ['id' => $paste->getId()]));
} }
} }
@ -73,7 +73,7 @@ class PasteController extends Controller
private function createCreateForm(Copypaste $entity) private function createCreateForm(Copypaste $entity)
{ {
$form = $this->createForm(CopypasteType::class, $entity, [ $form = $this->createForm(CopypasteType::class, $entity, [
'action' => $this->generateUrl('copypaste_create'), 'action' => $this->generateUrl('paste_create'),
'method' => 'POST', 'method' => 'POST',
]); ]);
@ -92,7 +92,7 @@ class PasteController extends Controller
$paste = new Copypaste(); $paste = new Copypaste();
$createForm = $this->createCreateForm($paste); $createForm = $this->createCreateForm($paste);
return $this->render('SkobkinCopyPasteBundle:Copypaste:new.html.twig', [ return $this->render('Paste/new.html.twig', [
'entity' => $paste, 'entity' => $paste,
'form_create' => $createForm->createView(), 'form_create' => $createForm->createView(),
]); ]);
@ -103,12 +103,12 @@ class PasteController extends Controller
* *
* @return Response * @return Response
*/ */
public function showAction($id, $secret) public function showAction(int $id, ?string $secret, HighlighterInterface $highlighter)
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
/* @var $paste Copypaste */ /* @var $paste Copypaste */
$paste = $em->getRepository('SkobkinCopyPasteBundle:Copypaste')->findOneBy([ $paste = $em->getRepository(Copypaste::class)->findOneBy([
'id' =>$id, 'id' =>$id,
'secret' => $secret 'secret' => $secret
]); ]);
@ -119,15 +119,12 @@ class PasteController extends Controller
$editForm = $this->createCreateForm($paste); $editForm = $this->createCreateForm($paste);
/* @var $highlighter GeshiHighlighter */
$highlighter = $this->get('dt_geshi.highlighter');
$highlightedCode = $highlighter->highlight($paste->getText(), $paste->getLanguage()->getCode(), function(GeSHi $geshi) { $highlightedCode = $highlighter->highlight($paste->getText(), $paste->getLanguage()->getCode(), function(GeSHi $geshi) {
$geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS); $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
}); });
return $this->render('SkobkinCopyPasteBundle:Copypaste:show.html.twig', [ return $this->render('Paste/show.html.twig', [
'paste' => $paste, 'paste' => $paste,
'highlighted_text' => $highlightedCode, 'highlighted_text' => $highlightedCode,
'form_create' => $editForm->createView(), 'form_create' => $editForm->createView(),
@ -143,15 +140,13 @@ class PasteController extends Controller
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$pastes = $em->getRepository('SkobkinCopyPasteBundle:Copypaste')->findBy( $pastes = $em->getRepository(Copypaste::class)->findBy(
['secret' => null], ['secret' => null],
['id' => 'DESC'], ['id' => 'DESC'],
// @todo move to the config // @todo move to the config
15 15
); );
return $this->render('::sidebar.html.twig', ['pastes' => $pastes]); return $this->render('sidebar.html.twig', ['pastes' => $pastes]);
} }
} }

View File

@ -23,6 +23,5 @@ class SkobkinCopyPasteExtension extends Extension
$config = $this->processConfiguration($configuration, $configs); $config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
} }
} }

View File

@ -1,3 +0,0 @@
skobkin_copy_paste:
resource: "@SkobkinCopyPasteBundle/Resources/config/routing/copypaste.yml"
prefix: /

View File

@ -1,21 +0,0 @@
copypaste_show_public:
path: /{id}
defaults: { _controller: 'Skobkin\Bundle\CopyPasteBundle\Controller\PasteController::showAction', secret: null }
requirements:
id: \d+
copypaste_show_private:
path: /{id}/{secret}
defaults: { _controller: 'Skobkin\Bundle\CopyPasteBundle\Controller\PasteController::showAction' }
requirements:
id: \d+
secret: \w{16}
copypaste_new:
path: /
defaults: { _controller: 'Skobkin\Bundle\CopyPasteBundle\Controller\PasteController::newAction' }
copypaste_create:
path: /create
defaults: { _controller: 'Skobkin\Bundle\CopyPasteBundle\Controller\PasteController::createAction' }
methods: POST

View File

@ -1,6 +0,0 @@
{% extends '::base.html.twig' %}
{% block content %}
{# This form recieves form_create object from current context #}
{% include 'SkobkinCopyPasteBundle:Form:form_paste_create.html.twig' %}
{% endblock %}