Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
technobel.sf
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mathieu
technobel.sf
Commits
971d4bb1
Commit
971d4bb1
authored
May 28, 2018
by
Mat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduction aux services dans symfony
parent
97d34921
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
4 deletions
+73
-4
app/config/services.yml
app/config/services.yml
+10
-0
src/TechnoBundle/Controller/DefaultController.php
src/TechnoBundle/Controller/DefaultController.php
+9
-3
src/TechnoBundle/Resources/views/Default/hello.html.twig
src/TechnoBundle/Resources/views/Default/hello.html.twig
+8
-1
src/TechnoBundle/Services/MonService.php
src/TechnoBundle/Services/MonService.php
+46
-0
No files found.
app/config/services.yml
View file @
971d4bb1
...
...
@@ -33,3 +33,13 @@ services:
# AppBundle\Service\ExampleService:
# arguments:
# $someArgument: 'some_value'
TechnoBundle\
:
resource
:
'
../../src/TechnoBundle/*'
exclude
:
'
../../src/TechnoBundle/{Entity,Repository,Tests}'
TechnoBundle\Services\MonService
:
arguments
:
$userManager
:
'
@fos_user.user_manager'
src/TechnoBundle/Controller/DefaultController.php
View file @
971d4bb1
...
...
@@ -2,7 +2,7 @@
namespace
TechnoBundle\Controller
;
use
Symfony\Bundle\FrameworkBundle\Controller\Controller
;
use
TechnoBundle\Services\MonService
;
class
DefaultController
extends
MasterController
{
...
...
@@ -28,12 +28,18 @@ class DefaultController extends MasterController
/**
* @param $service
* @param $name
* @return \Symfony\Component\HttpFoundation\Response
*/
public
function
helloAction
(
$name
)
public
function
helloAction
(
MonService
$service
,
$name
)
{
return
$this
->
render
(
'@Techno/Default/hello.html.twig'
,
array
(
'name'
=>
$name
));
return
$this
->
render
(
'@Techno/Default/hello.html.twig'
,
array
(
'name'
=>
$name
,
'randomNumber'
=>
$service
->
randomNumber
(),
'users'
=>
$service
->
getFOSUsers
(),
'messages'
=>
$service
->
getRandomMessage
(),
));
}
...
...
src/TechnoBundle/Resources/views/Default/hello.html.twig
View file @
971d4bb1
...
...
@@ -51,6 +51,13 @@
{%
endfor
%}
</table>
{{
dump
()
}}
<h3>
Service
</h3>
{{
randomNumber
}}
<br>
{%
for
user
in
users
%}
{{
user.username
}}
<br>
{%
endfor
%}
{{
messages
}}
{%
endblock
%}
src/TechnoBundle/Services/MonService.php
0 → 100755
View file @
971d4bb1
<?php
/**
* Created by PhpStorm.
* User: mat
* Date: 28/05/18
* Time: 9:37
*/
namespace
TechnoBundle\Services
;
use
FOS\UserBundle\Model\UserManager
;
class
MonService
{
private
$fos_users
;
public
function
getRandomMessage
()
{
$messages
=
array
(
'message 1'
,
'message 2'
,
'message 3'
,
'message 4'
,
'message 5'
,
'message 6'
,
);
$index
=
array_rand
(
$messages
);
return
$messages
[
$index
];
}
public
function
__construct
(
UserManager
$userManager
)
{
return
$this
->
fos_users
=
$userManager
;
}
public
function
getFOSUsers
()
{
return
$this
->
fos_users
->
findUsers
();
}
public
function
randomNumber
()
{
return
rand
(
0
,
100
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment