File tree Expand file tree Collapse file tree 3 files changed +41
-10
lines changed Expand file tree Collapse file tree 3 files changed +41
-10
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,11 @@ services:
4
4
5
5
app.repository.post :
6
6
class : AppBundle\Repository\PostRepository
7
- arguments : ['%kernel.root_dir%']
7
+ arguments : ['%kernel.root_dir%', '@markdown' ]
8
8
9
9
app.repository.psr :
10
10
class : AppBundle\Repository\PsrRepository
11
- arguments : ['%kernel.root_dir%']
11
+ arguments : ['%kernel.root_dir%', '@markdown' ]
12
12
13
13
app.twig.app_extension :
14
14
class : AppBundle\Twig\AppExtension
Original file line number Diff line number Diff line change 8
8
9
9
class PostRepository
10
10
{
11
+ /**
12
+ * @var string
13
+ */
14
+ private $ path ;
15
+
16
+ /**
17
+ * @var Parser
18
+ */
19
+ private $ parser ;
20
+
11
21
/**
12
22
* PostRepository constructor.
13
23
*
14
24
* @param string $kernelRootDir
25
+ * @param Parser $parser
15
26
*/
16
- public function __construct ($ kernelRootDir )
27
+ public function __construct ($ kernelRootDir, Parser $ parser )
17
28
{
18
29
$ this ->path = $ kernelRootDir ;
30
+ $ this ->parser = $ parser ;
19
31
}
20
32
33
+ /**
34
+ * Gets all Blog posts.
35
+ *
36
+ * @return array
37
+ */
21
38
public function findAll ()
22
39
{
23
40
$ finder = new Finder ();
@@ -89,8 +106,7 @@ public function getPostByFile($file)
89
106
return null ;
90
107
}
91
108
92
- $ parser = new Parser ();
93
- $ document = $ parser ->parse (file_get_contents ($ file ));
109
+ $ document = $ this ->parser ->parse (file_get_contents ($ file ));
94
110
95
111
$ post = new Post ();
96
112
$ post ->setTitle ($ document ->getYaml ()['title ' ]);
Original file line number Diff line number Diff line change 8
8
9
9
class PsrRepository
10
10
{
11
- public function __construct ($ kernelRootDir )
11
+ /**
12
+ * @var string
13
+ */
14
+ private $ path ;
15
+
16
+ /**
17
+ * @var Parser
18
+ */
19
+ private $ parser ;
20
+
21
+ /**
22
+ * PsrRepository constructor.
23
+ *
24
+ * @param $kernelRootDir
25
+ * @param Parser $parser
26
+ */
27
+ public function __construct ($ kernelRootDir , Parser $ parser )
12
28
{
13
29
$ this ->path = $ kernelRootDir ;
30
+ $ this ->parser = $ parser ;
14
31
}
15
32
16
33
/**
@@ -43,9 +60,8 @@ public function findOneBySlug($slug)
43
60
$ finder ->files ()->in ($ this ->path .'/../vendor/symfony-si/fig-standards-sl/accepted ' )->name ("*.md " );
44
61
$ finder ->sortByName ();
45
62
46
- $ parser = new Parser ();
47
63
foreach ($ finder as $ file ) {
48
- $ document = $ parser ->parse ($ file ->getContents ());
64
+ $ document = $ this -> parser ->parse ($ file ->getContents ());
49
65
if ($ document ->getYAML ()['slug ' ] == $ slug ) {
50
66
return $ this ->getPsrByFile ($ file ->getRealPath ());
51
67
}
@@ -88,8 +104,7 @@ public function getPsrByFile($file)
88
104
*/
89
105
private function getPsrByFileWithoutChilds ($ file )
90
106
{
91
- $ parser = new Parser ();
92
- $ document = $ parser ->parse (file_get_contents ($ file ));
107
+ $ document = $ this ->parser ->parse (file_get_contents ($ file ));
93
108
94
109
$ psr = new Psr ();
95
110
$ psr ->setTitle ($ document ->getYAML ()['title ' ]);
You can’t perform that action at this time.
0 commit comments