diff --git a/app/bootstrap.php.d/00-main.php b/app/bootstrap.php.d/00-main.php index 86d5573..3a731bf 100644 --- a/app/bootstrap.php.d/00-main.php +++ b/app/bootstrap.php.d/00-main.php @@ -5,3 +5,4 @@ use Gist\Application; $app = Application::getInstance(); $app['root_path'] = __DIR__ . '/../..'; + diff --git a/app/bootstrap.php.d/10-config.php b/app/bootstrap.php.d/10-config.php index f090b64..2fa307e 100644 --- a/app/bootstrap.php.d/10-config.php +++ b/app/bootstrap.php.d/10-config.php @@ -2,8 +2,10 @@ use Symfony\Component\Config\FileLocator; -$app['config.locator.path'] = $app['root_path'].'/app/config'; +$app['config.locator.path'] = $app['root_path'].'/app/config/'; $app['config.locator'] = function ($app) { return new FileLocator($app['config.locator.path']); }; + +$app['env'] = 'dev'; diff --git a/app/bootstrap.php.d/20-error.php b/app/bootstrap.php.d/20-error.php index 02de3a9..e32b2a0 100644 --- a/app/bootstrap.php.d/20-error.php +++ b/app/bootstrap.php.d/20-error.php @@ -10,3 +10,4 @@ $app->error(function (Exception $e, $code) use ($app) { ) ); }); + diff --git a/app/bootstrap.php.d/20-routing.php b/app/bootstrap.php.d/20-routing.php index dfeb2fe..e422277 100644 --- a/app/bootstrap.php.d/20-routing.php +++ b/app/bootstrap.php.d/20-routing.php @@ -12,3 +12,4 @@ $app['routes'] = $app->extend('routes', function ($routes, $app) { $routes->addCollection($app['routing.loader']->load($app['routing.file'])); return $routes; }); + diff --git a/app/bootstrap.php.d/20-twig.php b/app/bootstrap.php.d/20-twig.php index df3ce3f..3c1c7c1 100644 --- a/app/bootstrap.php.d/20-twig.php +++ b/app/bootstrap.php.d/20-twig.php @@ -11,3 +11,4 @@ $app->extend('twig', function ($twig, $app) { return $twig; }); + diff --git a/app/bootstrap.php.d/40-form.php b/app/bootstrap.php.d/40-form.php new file mode 100644 index 0000000..0abdab6 --- /dev/null +++ b/app/bootstrap.php.d/40-form.php @@ -0,0 +1,7 @@ +register(new FormServiceProvider()); +$app->register(new ValidatorServiceProvider()); diff --git a/app/bootstrap.php.d/50-git.php b/app/bootstrap.php.d/50-git.php new file mode 100644 index 0000000..3d7cf11 --- /dev/null +++ b/app/bootstrap.php.d/50-git.php @@ -0,0 +1,9 @@ + */ class HomeController { public function indexAction(Request $request, Application $app) { - return $app['twig']->render('Home/index.html.twig'); + $form = new CreateGistForm($app['form.factory'], $app['translator']); + $form = $form->build(); + + return $app['twig']->render( + 'Home/index.html.twig', + array( + 'form' => $form->createView(), + ) + ); } } diff --git a/src/Gist/Form/AbstractForm.php b/src/Gist/Form/AbstractForm.php new file mode 100644 index 0000000..220d7d4 --- /dev/null +++ b/src/Gist/Form/AbstractForm.php @@ -0,0 +1,26 @@ + + */ +abstract class AbstractForm +{ + protected $builder; + + protected $translator; + + public function __construct(FormFactory $formFactory, Translator $translator) + { + $this->translator = $translator; + + $this->builder = $formFactory->createBuilder('form'); + } + + abstract public function build(array $options = array()); +} diff --git a/src/Gist/Form/CreateGistForm.php b/src/Gist/Form/CreateGistForm.php new file mode 100644 index 0000000..f2cd917 --- /dev/null +++ b/src/Gist/Form/CreateGistForm.php @@ -0,0 +1,93 @@ + + */ +class CreateGistForm extends AbstractForm +{ + public function build(array $options = array()) + { + $this->builder->add( + 'title', + 'text', + array( + 'required' => false, + 'attr' => array( + 'class' => 'form-control', + 'placeholder' => $this->translator->trans('form.title.placeholder'), + ), + ) + ); + + $this->builder->add( + 'content', + 'textarea', + array( + 'required' => true, + 'attr' => array( + 'class' => 'form-control', + 'rows' => 10, + ), + 'constraints' => array( + new NotBlank(), + ), + ) + ); + + $this->builder->add( + 'type', + 'choice', + array( + 'required' => true, + 'choices' => $this->getTypes(), + 'constraints' => array( + new NotBlank(), + ), + ) + ); + + $this->builder->add( + 'cipher', + 'choice', + array( + 'required' => true, + 'choices' => array( + 0 => $this->translator->trans('form.cipher.choice.no'), + 1 => $this->translator->trans('form.cipher.choice.yes'), + ), + ) + ); + + return $this->builder->getForm(); + } + + protected function getTypes() + { + $types = array( + 'xml' => '', + 'css' => '', + 'js' => '', + 'php' => '', + 'sql' => '', + 'yaml'=> '', + 'perl' => '', + 'c' => '', + 'asp' => '', + 'python' => '', + 'bash' => '', + 'as' => '', + 'text' => '', + ); + + foreach ($types as $k => $v) { + $types[$k] = $this->translator->trans('form.type.choice.'.$k); + } + + return $types; + } +} diff --git a/src/Gist/Resources/views/Home/index.html.twig b/src/Gist/Resources/views/Home/index.html.twig index 1503ec7..2cc91ca 100644 --- a/src/Gist/Resources/views/Home/index.html.twig +++ b/src/Gist/Resources/views/Home/index.html.twig @@ -1 +1,91 @@ {% extends 'base.html.twig' %} + +{% block body %} +
+ + En activant le chiffrement, le code déposé ne pourra pas être forké. +
+ ++ +
++ +
+- - En activant le chiffrement, le code déposé ne pourra pas être forké. -
- -- -
-- -
-In file "{{ exception.file }}" at line {{ exception.line }}
-In file "{{ exception.file }}" at line {{ exception.line }}
-{{ exception.message }}
- -{{ exception.traceAsString }}+
{{ exception.traceAsString }}+ {% else %} +
{{ exception.message }}
+ {% endif %} +