Refactoring for symfony/flex. It finally works.

This commit is contained in:
Alexey Skobkin 2019-01-20 07:11:30 +03:00
parent 713099333c
commit 969fea6eb3
17 changed files with 173 additions and 66 deletions

View file

@ -28,6 +28,7 @@
"symfony/security-bundle": "^4.2",
"symfony/translation": "^4.2",
"symfony/twig-bundle": "^4.2",
"symfony/validator": "^4.2",
"symfony/yaml": "^4.2",
"theodordiaconu/geshi": "dev-master",
"theodordiaconu/geshi-bundle": "dev-master"

91
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "12a1646d5d2aeff9249a996492e96c85",
"content-hash": "b2efcf2213eb068842d3ad2b85667014",
"packages": [
{
"name": "doctrine/annotations",
@ -4009,6 +4009,95 @@
"homepage": "https://symfony.com",
"time": "2019-01-03T09:07:35+00:00"
},
{
"name": "symfony/validator",
"version": "v4.2.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/validator.git",
"reference": "f89d2fab883a6a20d0d0093537392763cf52f0ba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/validator/zipball/f89d2fab883a6a20d0d0093537392763cf52f0ba",
"reference": "f89d2fab883a6a20d0d0093537392763cf52f0ba",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"symfony/contracts": "^1.0.2",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0"
},
"conflict": {
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
"symfony/dependency-injection": "<3.4",
"symfony/http-kernel": "<3.4",
"symfony/intl": "<4.1",
"symfony/translation": "<4.2",
"symfony/yaml": "<3.4"
},
"require-dev": {
"doctrine/annotations": "~1.0",
"doctrine/cache": "~1.0",
"egulias/email-validator": "^1.2.8|~2.0",
"symfony/cache": "~3.4|~4.0",
"symfony/config": "~3.4|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/expression-language": "~3.4|~4.0",
"symfony/http-foundation": "~4.1",
"symfony/http-kernel": "~3.4|~4.0",
"symfony/intl": "~4.1",
"symfony/property-access": "~3.4|~4.0",
"symfony/translation": "~4.2",
"symfony/var-dumper": "~3.4|~4.0",
"symfony/yaml": "~3.4|~4.0"
},
"suggest": {
"doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.",
"doctrine/cache": "For using the default cached annotation reader and metadata cache.",
"egulias/email-validator": "Strict (RFC compliant) email validation",
"psr/cache-implementation": "For using the metadata cache.",
"symfony/config": "",
"symfony/expression-language": "For using the Expression validator",
"symfony/http-foundation": "",
"symfony/intl": "",
"symfony/property-access": "For accessing properties within comparison constraints",
"symfony/translation": "For translating validation errors.",
"symfony/yaml": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Validator\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Validator Component",
"homepage": "https://symfony.com",
"time": "2019-01-06T14:13:54+00:00"
},
{
"name": "symfony/var-exporter",
"version": "v4.2.2",

View file

@ -8,3 +8,11 @@ doctrine:
charset: 'UTF8'
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
mappings:
App\Entity:
type: annotation
dir: '%kernel.project_dir%/src/Entity'
is_bundle: false
prefix: App\Entity
alias: App

View file

@ -1,6 +1,5 @@
doctrine:
dbal:
dbname: "%test_database_name%"
port: "%test_database_port%"
user: "%test_database_user%"
password: "%test_database_password%"
#doctrine:
# dbal:
# driver: 'mysqli'
# url: '%env(resolve:DATABASE_URL)%'
# charset: 'UTF8'

View file

@ -0,0 +1,3 @@
framework:
validation:
email_validation_mode: html5

View file

@ -1,3 +1,7 @@
paste_new:
path: /
defaults: { _controller: 'App\Controller\PasteController::newAction' }
paste_show_public:
path: /{id}
defaults: { _controller: 'App\Controller\PasteController::showAction', secret: null }
@ -11,10 +15,6 @@ paste_show_private:
id: \d+
secret: \w{16}
paste_new:
path: /
defaults: { _controller: 'App\Controller\PasteController::newAction' }
paste_create:
path: /create
defaults: { _controller: 'App\Controller\PasteController::createAction' }

View file

@ -22,3 +22,7 @@ services:
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
# Overriding old bundle service definition
DT\Bundle\GeshiBundle\Highlighter\HighlighterInterface:
class: DT\Bundle\GeshiBundle\Highlighter\GeshiHighlighter

View file

@ -1,17 +1,27 @@
<?php
use Symfony\Component\Dotenv\Dotenv;
require dirname(__DIR__).'/vendor/autoload.php';
// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) {
$_SERVER += $env;
$_ENV += $env;
} elseif (!class_exists(Dotenv::class)) {
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
} else {
// load all the .env files
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Debug::enable();
}
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

View file

@ -3,7 +3,7 @@
namespace App\Command;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Copypaste;
use App\Entity\Paste;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@ -39,7 +39,7 @@ class DropExpiredPasteCommand extends Command
// @todo move to repository
$qb = $this->em->createQueryBuilder()
->delete(Copypaste::class, 'c')
->delete(Paste::class, 'c')
->where('c.dateExpire < :now')
->andWhere('c.dateExpire IS NOT NULL')
->setParameter('now', new \DateTime());

View file

@ -2,20 +2,21 @@
namespace App\Controller;
use Doctrine\ORM\EntityManagerInterface;
use DT\Bundle\GeshiBundle\Highlighter\HighlighterInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\{Request, Response};
use App\Entity\Copypaste;
use App\Form\CopypasteType;
use App\Entity\Paste;
use App\Form\PasteType;
use \GeSHi\GeSHi;
class PasteController extends AbstractController
{
public function createAction(Request $request): Response
{
$paste = new Copypaste();
$paste = new Paste();
$form = $this->createCreateForm($paste);
$form->handleRequest($request);
@ -58,7 +59,7 @@ class PasteController extends AbstractController
public function newAction(): Response
{
$paste = new Copypaste();
$paste = new Paste();
$createForm = $this->createCreateForm($paste);
return $this->render('Paste/new.html.twig', [
@ -67,12 +68,10 @@ class PasteController extends AbstractController
]);
}
public function showAction(int $id, ?string $secret, HighlighterInterface $highlighter): Response
public function showAction(int $id, ?string $secret, EntityManagerInterface $em, HighlighterInterface $highlighter): Response
{
$em = $this->getDoctrine()->getManager();
/* @var $paste \App\Entity\Copypaste */
$paste = $em->getRepository(Copypaste::class)->findOneBy([
/* @var $paste \App\Entity\Paste */
$paste = $em->getRepository(Paste::class)->findOneBy([
'id' =>$id,
'secret' => $secret
]);
@ -99,7 +98,7 @@ class PasteController extends AbstractController
{
$em = $this->getDoctrine()->getManager();
$pastes = $em->getRepository(Copypaste::class)->findBy(
$pastes = $em->getRepository(Paste::class)->findBy(
['secret' => null],
['id' => 'DESC'],
// @todo move to the config
@ -109,9 +108,9 @@ class PasteController extends AbstractController
return $this->render('sidebar.html.twig', ['pastes' => $pastes]);
}
private function createCreateForm(Copypaste $entity): FormInterface
private function createCreateForm(Paste $entity): FormInterface
{
$form = $this->createForm(CopypasteType::class, $entity, [
$form = $this->createForm(PasteType::class, $entity, [
'action' => $this->generateUrl('paste_create'),
'method' => 'POST',
]);

View file

@ -6,14 +6,12 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Copypaste
*
* @ORM\Table(name="copypastes", indexes={
* @ORM\Index(name="idx_expire", columns={"date_expire"})
* })
* @ORM\Entity
*/
class Copypaste
class Paste
{
/**
* @var integer
@ -111,7 +109,7 @@ class Copypaste
return $this;
}
public function getText(): string
public function getText(): ?string
{
return $this->text;
}
@ -135,7 +133,7 @@ class Copypaste
return $this;
}
public function getLanguage(): Language
public function getLanguage(): ?Language
{
return $this->language;
}

View file

@ -9,11 +9,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class FakeCaptchaType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([

View file

@ -2,25 +2,17 @@
namespace App\Form;
use App\Entity\Copypaste;
use App\Entity\Language;
use App\Entity\{Paste, Language};
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\{CheckboxType, ChoiceType, TextareaType, TextType};
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
class CopypasteType extends AbstractType
class PasteType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
@ -83,7 +75,7 @@ class CopypasteType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Copypaste::class
'data_class' => Paste::class
]);
}
}

View file

@ -317,6 +317,15 @@
"ref": "369b5b29dc52b2c190002825ae7ec24ab6f962dd"
}
},
"symfony/validator": {
"version": "4.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "4.1",
"ref": "0cdc982334f45d554957a6167e030482795bf9d7"
}
},
"symfony/var-dumper": {
"version": "v4.2.2"
},

View file

@ -1,4 +1,4 @@
{% block copypaste_fake_captcha_widget %}
{% block fake_captcha_widget %}
{% spaceless %}
<div id="{{ form.vars.id }}"></div>
<script type="text/javascript">

View file

@ -2,11 +2,11 @@
{%- block css -%}
{{- parent() -}}
<link href="{{ asset('/css/base.css') }}" rel="stylesheet" media="screen">
<link href="/css/base.css" rel="stylesheet" media="screen">
{% endblock %}
{% block javascript %}
{{- parent() -}}
<script src="{{ asset('/js/copypaste.js') }}"></script>
<script src="/js/copypaste.js"></script>
{% endblock %}
{%- block header -%}

View file

@ -4,7 +4,7 @@
{%- block head -%}
<title>{% block title %}CopyPaste{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="{{ asset('/images/favicon.ico') }}">
<link rel="icon" href="/images/favicon.ico">
{%- block css -%}
<link href="https://yastatic.net/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" media="screen">
{%- endblock -%}