...
 
Commits (92)
......@@ -16,6 +16,8 @@
!/var/SymfonyRequirements.php
/vendor/
/web/bundles/
/web/assets/
/config/jwt/
## ?? GIT or NOT GIT ??
bin/
......
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Bière</title>
</head>
<body>
<h2>Bière</h2>
<form id="biere">
<label for="nom">Nom</label>
<input type="text" name="nom"><br>
<label for="degre">Degré</label>
<input type="text" name="degre"><br>
<label for="capacite">Capacité</label>
<input type="text" name="capacite"><br>
<label for="brasserie">Brasserie</label>
<select name="brasserie">
</select><br>
<label for="file">Image</label>
<input type="file" name="file"><br>
<button id="send">Envoyer</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
// select, liste des brasseries
$.get(
"http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie",
function(data){
for (let item of data) {
$('select[name=brasserie]').append(
`<option value="${item.id}">${item.nom}</option>`
);
}
}
);
// submit du formulaire, en POST (create)
$('#send').click(function(e) {
e.preventDefault();
let form = new FormData($('#biere')[0]);
console.log(form);
$.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/biere",
method: 'POST',
data: form,
dataType: 'JSON',
cache: false,
contentType: false,
processData: false,
success: function(data) {
console.log(data);
},
error: function(xhr) {
console.log(xhr);
}
});
});
});
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Brasserie</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<!-- MODALE BOOTSTRAP -->
<div class="modal" data-backdrop="static" keyboard="false">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Login</h5>
</div>
<form id="form-login">
<div class="modal-body">
<label for="username">Nom d'utilisteur</label>
<input name="username" type="text" class="form-control">
<label for="password">Mot de passe</label>
<input name="password" type="password" class="form-control">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Se connecter</button>
</div>
</form>
</div>
</div>
</div>
<!-- -->
<h2>Brasserie</h2>
<select id="pays"></select>
<ul id="brasserie"></ul>
<button id="new">New</button>
<form id="form">
Nom <input type="text" name="nom"><br>
Adresse <input type="text" name="adresse"><br>
Pays <input type="text" name="pays"><br>
<button id="send">Enregistrer</button>
</form>
<button id="delete">Supprimer</button>
<script>
$(document).ready(function()
{
let targetedId;
// automatise l'authentification avant chaque requête ajax
$.ajaxPrefilter(function(options) {
if (!options.beforeSend) {
options.beforeSend = function(xhr) {
// avec 2 espaces entre bearer et le token !!!!
xhr.setRequestHeader('Authorization', 'bearer ' + sessionStorage.getItem('token'));
}
}
});
// au submit du formulaire de connexion
$('#form-login button').click(function(e)
{
e.preventDefault();
let username = $('input[name=username]').val();
let password = $('input[name=password]').val();
$.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/login_check",
dataType: 'JSON',
method: 'POST',
data: JSON.stringify({"username": username, "password": password}),
success: function(data) {
sessionStorage.setItem('token', data.token);
token = sessionStorage.getItem('token');
$('.modal').modal('hide');
},
error: function(xhr) {
alert('login failed');
}
});
});
// pas de token, affiche la modale de connexion
let token = sessionStorage.getItem('token');
if (token === null) {
// affiche une page de connexion
$('.modal').modal();
}
//console.log(token);
// supprime une brasserie
$('#delete').click(function(e)
{
e.preventDefault();
$.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie/" + targetedId,
dataType: 'JSON',
method: 'DELETE',
success: function(data)
{
alert('success');
$("li[data-target="+ targetedId +"]").remove();
targetedId = undefined;
},
error: (xhr) => {
console.log(xhr);
}
});
});
// charge le select avec la liste des pays
$.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/pays/used",
method: 'GET',
dataType: 'JSON',
success: function(data) {
for (let elem of data) {
$('#pays').append(
`<option value="${elem.id}">${elem.nom}</option>`
);
}
},
error: (error) => {
console.log(error);
}
});
// la liste des brasseries s'adapte quand on choisit le pays
$('#pays').change(function(e) {
$.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie/parPays/" + $(this).val(),
dataType: 'JSON',
method: 'GET',
success: data => {
$('#brasserie').empty();
for (let elem of data) {
$('#brasserie').append(
`<li data-target="${elem.id}">${elem.nom}</li>`
);
}
}
});
});
// clicker sur le bouton new vide le formulaire
$('#new').click(function(e) {
e.preventDefault();
targetedId = undefined;
$('input').val('');
});
// charge la liste des brasseries
$.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie",
dataType: 'JSON',
method: 'GET',
success: function(data) {
for (let elem of data)
{
$('#brasserie').append(
`<li data-target="${elem.id}">${elem.nom}</li>`
);
}
}
});
// charge les données dans le formulaire lorsqu'on clique sur une brasserie
$('#brasserie').on('click', 'li', function()
{
targetedId = $(this).attr('data-target');
$.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie/" + targetedId,
method: 'GET',
success: function(data) {
$('input[name=nom]').val(data.nom);
$('input[name=adresse]').val(data.adresse);
$('input[name=pays]').val(data.pays.id);
},
error: function(xhr) {
console.log(xhr);
}
});
});
// submit du formulaire, en put (update) ou en post (create)
$('#send').click(function(e)
{
e.preventDefault();
$.ajax({
url: "http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie" + (targetedId !== undefined ? '/' + targetedId : ''),
dataType: 'JSON',
method: (targetedId !== undefined ? 'PUT' : 'POST'),
data: $('#form').serialize(),
success: function(data) {
alert('success');
// le callback ajoute la nouvelle brasserie dans la liste
if (targetedId === undefined)
{
$('#brasserie').append(
`<li data-target="${data.id}">${data.nom}</li>`
);
}
},
error: function(xhr) {
console.log(xhr);
alert('error');
}
});
});
});
</script>
</body>
</html>
......@@ -22,6 +22,11 @@ class AppKernel extends Kernel
new JMS\SerializerBundle\JMSSerializerBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
new FOS\UserBundle\FOSUserBundle(),
new SocketBundle\SocketBundle(),
new Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle(),
new FOS\RestBundle\FOSRestBundle(),
new Nelmio\CorsBundle\NelmioCorsBundle(),
new Api2Bundle\Api2Bundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
......
......@@ -7,6 +7,7 @@
<script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">
{% block stylesheets %}{% endblock %}
<link rel="stylesheet" type="text/css" href="{{ asset('css/style.css') }}">
......@@ -18,6 +19,7 @@
{% block layout %}{% endblock %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
{% block javascripts %}{% endblock %}
</body>
......
......@@ -5,11 +5,15 @@ imports:
- { resource: "@TechnoBundle/Resources/config/services.yml" }
- { resource: "@AssoBundle/Resources/config/services.yml" }
- { resource: "@APIBundle/Resources/config/services.yml" }
- { resource: "@SocketBundle/Resources/config/services.yml" }
- { resource: "@Api2Bundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: fr
avatar_directory: "%kernel.project_dir%/web/assets/img/avatar"
biere_directory: "%kernel.project_dir%/web/assets/img/biere"
framework:
#esi: ~
......@@ -21,7 +25,7 @@ framework:
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
serializer: { enable_annotations: true, enabled: false }
default_locale: '%locale%'
trusted_hosts: ~
session:
......@@ -88,3 +92,39 @@ fos_user:
from_email:
address: mat@collectifs.net
sender_name: admin
# JWT token authentification
lexik_jwt_authentication:
secret_key: '%kernel.project_dir%/config/jwt/private.pem' # required for token creation
public_key: '%kernel.project_dir%/config/jwt/public.pem' # required for token verification
pass_phrase: '1234' # required for token creation, usage of an environment variable is recommended
token_ttl: 3600
# Nelmio CORS
nelmio_cors:
paths:
'^/API/':
allow_origin: ['*']
allow_headers: ['X-Custom-Auth']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE', 'PATCH']
max_age: 3600
# JMS serializer
jms_serializer:
handlers:
datetime:
default_format: "d/m/Y"
# FOS Rest
fos_rest:
body_converter:
enabled: true
zone:
- { path: "^/API" }
format_listener:
rules:
- { path: "^/API", priorities: [json], fallback_format: 'json' }
view:
view_response_listener: true
failed_validation: HTTP_BAD_REQUEST
\ No newline at end of file
api2:
resource: "@Api2Bundle/Controller/"
type: annotation
prefix: /API/v2
api_login_check:
path: /API/login_check
socket:
resource: "@SocketBundle/Controller/"
type: annotation
prefix: /
logout:
path: /logout
login-check:
path: /login-check
###
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
......@@ -16,10 +37,10 @@ techno:
### fos_userbundle
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
prefix: /user
fos_user_group:
resource: "@FOSUserBundle/Resources/config/routing/group.xml"
prefix: /group
# fos_user:
# resource: "@FOSUserBundle/Resources/config/routing/all.xml"
# prefix: /user
#
# fos_user_group:
# resource: "@FOSUserBundle/Resources/config/routing/group.xml"
# prefix: /group
security:
# fournisseur d'utilisateurs
providers:
main:
entity:
class: SocketBundle\Entity\User
property: username
# quelle est la propriété qui servira de username, typiquement username ou email, doit être unique
# other: ...
# si on a plusieurs fournisseurs
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
SocketBundle\Entity\User:
algorithm: bcrypt
iterations: 4678
# le nbre de fois que le mot de passe est re-crypté lui-même. aujourd'hui on conseille entre 4 et 5000
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
login:
pattern: ^/(login|register)$
anonymous: true
api_login:
pattern: ^/API/login
stateless: true
anonymous: true
json_login:
check_path: /API/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
dev:
pattern: ^/(_profiler|_wdt|css|images|js)/
security: false
api:
pattern: ^/API/
stateless: true
anonymous: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
main:
pattern: ^/
anonymous: true
anonymous: true
# un anonyme n'aura accès qu'aux pages login et register
form_login:
provider: fos_userbundle
login_path: fos_user_security_login
check_path: fos_user_security_check
default_target_path: techno_homepage
use_referer : true
csrf_token_generator: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
login_path: login
check_path: login-check # une route ou un chemin
default_target_path: chat_message
# ce sera souvent la page d'accueil
always_use_default_target_path: true
logout:
path: fos_user_security_logout
target: fos_user_security_login
path: logout
target: login
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/asso/, role: ROLE_ADMIN }
......@@ -16,18 +16,18 @@ services:
# 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
#AppBundle\:
#resource: '../../src/AppBundle/*'
SocketBundle\:
resource: '../../src/SocketBundle/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
#exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
exclude: '../../src/SocketBundle/{Entity,Repository,Tests}'
# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
#AppBundle\Controller\:
#resource: '../../src/AppBundle/Controller'
#public: true
#tags: ['controller.service_arguments']
SocketBundle\Controller\:
resource: '../../src/SocketBundle/Controller'
public: true
tags: ['controller.service_arguments']
# add more services, or override services that need manual wiring
# AppBundle\Service\ExampleService:
......
......@@ -6,7 +6,9 @@
"psr-4": {
"TechnoBundle\\": "src/TechnoBundle",
"AssoBundle\\": "src/AssoBundle",
"APIBundle\\": "src/APIBundle"
"APIBundle\\": "src/APIBundle",
"SocketBundle\\": "src/SocketBundle",
"Api2Bundle\\": "src/Api2Bundle"
},
"classmap": [
"app/AppKernel.php",
......@@ -23,12 +25,16 @@
},
"require": {
"php": ">=5.5.9",
"cboden/ratchet": "^0.4.1",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"friendsofsymfony/jsrouting-bundle": "^2.2",
"friendsofsymfony/rest-bundle": "^2.3",
"friendsofsymfony/user-bundle": "^2.1",
"incenteev/composer-parameter-handler": "^2.0",
"jms/serializer-bundle": "^2.3",
"lexik/jwt-authentication-bundle": "^2.5",
"nelmio/cors-bundle": "^1.5",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"symfony/monolog-bundle": "^3.1.0",
......
This diff is collapsed.
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
<?php
namespace Api2Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class Api2Bundle extends Bundle
{
}
<?php
namespace Api2Bundle\Controller;
use Api2Bundle\Entity\Biere;
use Api2Bundle\Form\BiereType;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\Request;
class BiereController extends FOSRestController
{
/**
* @param Request $request
* @Rest\Post(path="/biere")
* @Rest\View()
* @return Biere|\Symfony\Component\Form\FormInterface
*/
public function postAction(Request $request)
{
$biere = new Biere();
$form = $this->createForm(BiereType::class, $biere);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$file = $biere->getFile();
$uniquePath = md5(uniqid()). '_' . $file->getClientOriginalName();
$file->move($this->getParameter('biere_directory'), $uniquePath);
$biere->setImage($uniquePath);
$em = $this->getDoctrine()->getManager();
$em->persist($biere);
$em->flush();
return $biere;
}
return $form;
}
}
<?php
namespace Api2Bundle\Controller;
use Api2Bundle\Entity\Brasserie;
use Api2Bundle\Entity\Pays;
use Api2Bundle\Form\BrasserieType;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
/**
* Class BrasserieController
*
* @package Api2Bundle\Controller
* @Security("has_role('ROLE_USER')")
*/
class BrasserieController extends FOSRestController
{
/**
* @Rest\Get(path="/brasserie")
* @Rest\View(serializerGroups={"getBrasserie"})
*/
public function getAction(Request $request)
{
//dump($request); die;
return $this->getDoctrine()
->getRepository(Brasserie::class)
->findAll();
}
/**
* @param Request $request
* @param Brasserie $id
* @Rest\Put(path="/brasserie/{id}")
* @Rest\View()
* @return Brasserie|\Symfony\Component\Form\FormInterface
*/
public function putAction(Request $request, Brasserie $id)
{
// le fait de typer $id fait qu'il retourne un objet !
$form = $this->createForm(BrasserieType::class, $id,
array(
'method' => 'put'
)
);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->flush();
return $id;
}
return $form;
}
/**
* @param Brasserie $id
* @Rest\Get(path="/brasserie/{brasserieId}")
* @Rest\View()
* @return Brasserie
*/
public function getByIdAction(Brasserie $brasserieId)
{
return $brasserieId;
}
/**
* @param Request $request
* @Rest\Post(path="/brasserie")
* @Rest\View()
* @return Brasserie|\Symfony\Component\Form\FormInterface
*/
public function newAction(Request $request)
{
$brasserie = new Brasserie();
$form = $this->createForm(BrasserieType::class, $brasserie);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($brasserie);
$em->flush();
return $brasserie;
}
return $form;
}
/**
* @Rest\Get(path="/brasserie/parPays/{paysID}")
* @Rest\View()
* @return Brasserie[]
*/
public function getByCountryAction(Pays $paysID)
{
return $this->getDoctrine()
->getRepository(Brasserie::class)
->findBy(array('pays' => $paysID));
}
/**
* @param $id
* @Rest\Delete(path="/brasserie/{id}")
* @Rest\View()
* @return Brasserie
*/
public function deleteAction($id)
{
$em = $this->getDoctrine()->getManager();
$brasserie = $em->getRepository(Brasserie::class)
->find($id);
$em->remove($brasserie);
$em->flush();
return $brasserie;
}
}
<?php
namespace Api2Bundle\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use SocketBundle\Entity\Message;
use SocketBundle\Form\MessageType;
use Symfony\Component\HttpFoundation\Request;
class MessageController extends FOSRestController
{
/**
* @Rest\Get(path="/message")
* @Rest\View(serializerGroups={"getMessage"})
*/
public function getAction()
{
return $this->getDoctrine()
->getRepository(Message::class)
->findAll();
}
/**
* @param Request $request
* @Rest\Post(path="/message")
* @Rest\View()
* @return \Symfony\Component\Form\FormInterface
*/
public function postAction(Request $request)
{
$message = new Message();
$form = $this->createForm(MessageType::class, $message);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em = $this->getDoctrine()->getManager();
$message->setDate(new \DateTime()); // c'est mieux de mettre un prepersist dans l'entité
$em->persist($message);
$em->flush();
}
return $form;
}
}
<?php
namespace Api2Bundle\Controller;
use Api2Bundle\Entity\Brasserie;
use Api2Bundle\Entity\Pays;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
class PaysController extends FOSRestController
{
/**
* @Rest\Get(path="/pays/used")
* @Rest\View()
* @return Pays
*/
public function getUsedPaysAction()
{
$repo = $this->getDoctrine()
->getRepository(Brasserie::class);
$pays = array_map(function($brasserie) {
/**
* @var $brasserie Brasserie
*/
return $brasserie->getPays();
}, $repo->getPays());
return $pays;
}
}
<?php
namespace Api2Bundle\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use SocketBundle\Entity\User;
class UserController extends FOSRestController
{
/**
* @Rest\Get(path="/user")
* @Rest\View(serializerGroups={"getUser"})
*/
public function getAction()
{
return $this->getDoctrine()
->getRepository(User::class)
->findAll();
}
}
<?php
namespace Api2Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Biere
*
* @ORM\Table(name="biere")
* @ORM\Entity(repositoryClass="Api2Bundle\Repository\BiereRepository")
*/
class Biere
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var Categorie
* @ORM\ManyToOne(targetEntity="Api2Bundle\Entity\Categorie")
* @ORM\JoinColumn(name="id_categorie", nullable=true)
*/
private $categorie;
/**
* @var integer
* @ORM\ManyToOne(targetEntity="Api2Bundle\Entity\Brasserie")
* @ORM\JoinColumn(name="id_brasserie", nullable=false)
*/
private $brasserie;
/**
* @var string
* @ORM\Column(name="nom", type="string", length=255, nullable=false, unique=false)
*/
private $nom;
/**
* @var float
* @ORM\Column(name="degre", type="float", nullable=true, unique=false)
*/
private $degre;
/**
* @var float
* @ORM\Column(name="capacite", length=255, type="string", nullable=true, unique=false)
*/
private $capacite;
/**
* @var string
* @ORM\Column(name="image", type="string", length=255, nullable=true, unique=true)
*/
private $image;
/**
* @var UploadedFile
*
*/
private $file;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return Categorie
*/
public function getCategorie()
{
return $this->categorie;
}
/**
* @param Categorie $categorie
* @return Biere
*/
public function setCategorie($categorie)
{
$this->categorie = $categorie;
return $this;
}
/**
* @return int
*/
public function getBrasserie()
{
return $this->brasserie;
}
/**
* @param int $brasserie
* @return Biere
*/
public function setBrasserie($brasserie)
{
$this->brasserie = $brasserie;
return $this;
}
/**
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* @param string $nom
* @return Biere
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* @return float
*/
public function getDegre()
{
return $this->degre;
}
/**
* @param float $degre
* @return Biere
*/
public function setDegre($degre)
{
$this->degre = $degre;
return $this;
}
/**
* @return float
*/
public function getCapacite()
{
return $this->capacite;
}
/**
* @param float $capacite
* @return Biere
*/
public function setCapacite($capacite)
{
$this->capacite = $capacite;
return $this;
}
/**
* @return string
*/
public function getImage()
{
return $this->image;
}
/**
* @param string $image
* @return Biere
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* @return UploadedFile
*/
public function getFile()
{
return $this->file;
}
/**
* @param UploadedFile $file
* @return Biere
*/
public function setFile($file)
{
$this->file = $file;
return $this;
}
}
<?php
namespace Api2Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* Brasserie
*
* @ORM\Table(name="brasserie")
* @ORM\Entity(repositoryClass="Api2Bundle\Repository\BrasserieRepository")
*/
class Brasserie
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"getBrasserie"})
*/
private $id;
/**
* @var integer
* @ORM\ManyToOne(targetEntity="Api2Bundle\Entity\Pays")
* @ORM\JoinColumn(name="id_pays", nullable=false)
* @Serializer\Groups({"getBrasserie"})
*/
private $pays;
/**
* @var string
* @ORM\Column(name="nom", type="string", length=255)
* @Serializer\Groups({"getBrasserie"})
*/
private $nom;
/**
* @var string
* @ORM\Column(name="adresse", type="string", length=255, nullable=true)
* @Serializer\Groups({"getBrasserie"})
*/
private $adresse;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return int
*/
public function getPays()
{
return $this->pays;
}
/**
* @param int $pays
* @return Brasserie
*/
public function setPays($pays)
{
$this->pays = $pays;
return $this;
}
/**
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* @param string $nom
* @return Brasserie
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* @return string
*/
public function getAdresse()
{
return $this->adresse;
}
/**
* @param string $adresse
* @return Brasserie
*/
public function setAdresse($adresse)
{
$this->adresse = $adresse;
return $this;
}
}
<?php
namespace Api2Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Categorie
*
* @ORM\Table(name="categorie")
* @ORM\Entity(repositoryClass="Api2Bundle\Repository\CategorieRepository")
*/
class Categorie
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=255)
*/
private $nom;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* @param string $nom
* @return Categorie
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
}
<?php
namespace Api2Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* Pays
*
* @ORM\Table(name="pays")
* @ORM\Entity(repositoryClass="Api2Bundle\Repository\PaysRepository")
*/
class Pays
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"getBrasserie"})
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="isocode", type="string", length=255, unique=true)
*/
private $isocode;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=255)
* @Serializer\Groups({"getBrasserie"})
*/
private $nom;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getIsocode()
{
return $this->isocode;
}
/**
* @param string $isocode
* @return Pays
*/
public function setIsocode($isocode)
{
$this->isocode = $isocode;
return $this;
}
/**
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* @param string $nom
* @return Pays
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
}
<?php
namespace Api2Bundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class BiereType extends AbstractType
{