Completed
Push — master ( cc173b...1bbcf8 )
by Peter
21:26
created

src/AppBundle/Controller/DefaultController.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace AppBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\Form\Extension\Core\Type\EmailType;
8
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
9
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
10
use Symfony\Component\Form\Extension\Core\Type\TextType;
11
use Symfony\Component\HttpFoundation\RedirectResponse;
12
use Symfony\Component\HttpFoundation\Request;
13
use AppBundle\Entity\Contact;
14
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
15
use Symfony\Component\HttpFoundation\Response;
16
use Mni\FrontYAML\Parser;
17
use AppBundle\Entity\Project;
18
19
class DefaultController extends Controller
20
{
21
    /**
22
     * @Route("/", name="homepage")
23
     * @Cache(expires="tomorrow", public=true)
24
     */
25
    public function indexAction()
26
    {
27
        $posts = $this->get('app.repository.post')->findLatest();
28
29
        $jsonData = json_decode(file_get_contents('http://knpbundles.com/newest.json'), true);
30
31
        return $this->render('default/index.html.twig', [
32
            'posts' => $posts,
33
            'bundles' => $jsonData['results']
34
        ]);
35
    }
36
37
    /**
38
     * @Route("/copyrights", name="copyrights")
39
     * @param Request $request
40
     * @return Response
41
     */
42
    public function copyrightAction(Request $request)
43
    {
44
        return $this->render('default/copyright.html.twig');
45
    }
46
47
    /**
48
     * @Route("/join-us", name="join")
49
     * @param Request $request
50
     * @return Response
51
     */
52
    public function joinAction(Request $request)
53
    {
54
        return $this->render('default/join.html.twig');
55
    }
56
57
    /**
58
     * @Route("/contact", name="contact")
59
     * @Cache(maxage="20", public=true)
60
     *
61
     * @param Request $request
62
     * @return RedirectResponse|Response
63
     */
64
    public function contactAction(Request $request)
65
    {
66
        $contact = new Contact();
67
68
        $form = $this->createFormBuilder($contact)
69
            ->add('name', TextType::class)
70
            ->add('email', EmailType::class)
71
            ->add('message', TextareaType::class)
72
            ->add('send', SubmitType::class)
73
            ->getForm();
74
75
        $form->handleRequest($request);
76
77
        if($form->isValid()) {
78
            // send email to admin
79
            $message = \Swift_Message::newInstance()
80
                ->setSubject('Message from Symfony.si')
81
                ->setFrom($contact->getEmail())
82
                ->setTo($this->container->getParameter('symfonysi_admin_email'))
83
                ->setBody(
84
                    $this->renderView(
85
                        'emails/email.txt.twig',
86
                        [
87
                            'name' => $contact->getName(),
88
                            'email' => $contact->getEmail(),
89
                            'message' => $contact->getMessage()
90
                        ]
91
                    )
92
                )
93
            ;
94
            $this->get('mailer')->send($message);
95
96
            return $this->redirect($this->generateUrl('contact_success'));
97
        }
98
99
        return $this->render('default/contact.html.twig', [
100
            'form' => $form->createView(),
101
        ]);
102
    }
103
104
    /**
105
     * @Route("/contact-succeeded", name="contact_success")
106
     * @param Request $request
107
     * @return Response
108
     */
109
    public function contactSuccessAction(Request $request)
110
    {
111
        return $this->render('default/contactSuccess.html.twig');
112
    }
113
114
    /**
115
     * @Route("/contributors", name="contributors")
116
     * @param Request $request
117
     * @return Response
118
     */
119
    public function contributorsAction(Request $request)
120
    {
121
        $cache = $this->get('kernel')->getRootDir().'/../var/cache/github-api-cache';
122
        $client = new \Github\Client(
123
            new \Github\HttpClient\CachedHttpClient(['cache_dir' => $cache])
124
        );
125
        $srcContributors = $client->api('repo')->contributors('symfony-si', 'symfony.si');
126
        $docsContributors = $client->api('repo')->contributors('symfony-si', 'symfony-docs-sl');
127
        $mustWatchContributors = $client->api('repo')->contributors('symfony-si', 'symfony-must-watch');
128
        $contributors = [];
129
130
        foreach($srcContributors as $key=>$contributor) {
131
            $user = $client->api('user')->show($contributor['login']);
132
            $contributors[$contributor['login']] = [
133
                'name'       => ($user['name']) ? $user['name'] : $contributor['login'],
134
                'html_url'   => $user['html_url'],
135
                'avatar_url' => $user['avatar_url'],
136
            ];
137
        }
138
139
        foreach($docsContributors as $key=>$contributor) {
140
            $user = $client->api('user')->show($contributor['login']);
141
            $contributors[$contributor['login']] = [
142
                'name'       => ($user['name']) ? $user['name'] : $contributor['login'],
143
                'html_url'   => $user['html_url'],
144
                'avatar_url' => $user['avatar_url'],
145
            ];
146
        }
147
148
        foreach($mustWatchContributors as $key=>$contributor) {
149
            $user = $client->api('user')->show($contributor['login']);
0 ignored issues
show
The call to show() misses some required arguments starting with $repository.
Loading history...
The call to show() misses a required argument $repository.

This check looks for function calls that miss required arguments.

Loading history...
150
            $contributors[$contributor['login']] = [
151
                'name'       => ($user['name']) ? $user['name'] : $contributor['login'],
152
                'html_url'   => $user['html_url'],
153
                'avatar_url' => $user['avatar_url'],
154
            ];
155
        }
156
157
        return $this->render('default/contributors.html.twig', [
158
            'contributors' => $contributors
159
        ]);
160
    }
161
162
    /**
163
     * @Route("/resources", name="resources")
164
     * @param Request $request
165
     * @return Response
166
     */
167
    public function resourcesAction(Request $request)
168
    {
169
        $file = $this->get('kernel')->getRootDir().'/../vendor/symfony-si/symfony-resources/README.md';
170
        $content = (file_exists($file)) ? file_get_contents($file) : '<h1>Symfony resources</h1>';
171
        $parser = new Parser();
172
        $document = $parser->parse($content);
173
174
        return $this->render('default/resources.html.twig', ['html' => $document->getContent()]);
175
    }
176
177
    /**
178
     * @Route("/cheatsheet", name="cheatsheet")
179
     * @return Response
180
     */
181
    public function cheatsheetAction()
182
    {
183
        $file = $this->get('kernel')->getRootDir().'/../vendor/symfony-si/symfony-cheatsheet/README.md';
184
        $content = (file_exists($file)) ? file_get_contents($file) : '<h1>Symfony cheat sheet</h1>';
185
        $parser = new Parser();
186
        $document = $parser->parse($content);
187
188
        return $this->render('default/cheatsheet.html.twig', ['html' => $document->getContent()]);
189
    }
190
191
    /**
192
     * @Route("/ecosystem", name="ecosystem")
193
     * @return Response
194
     */
195
    public function ecosystemAction()
196
    {
197
        $projects = [];
198
        $project = new Project();
199
        $project->setTitle('Symfony Framework');
200
        $project->setDescription('Prevod ogrodja Symfony');
201
        $project->setLink('https://github.com/symfony/symfony');
202
        $project->setRepository('https://github.com/symfony/symfony');
203
        $project->setSlug('symfony');
204
        $projects[] = $project;
205
206
        $project = new Project();
207
        $project->setTitle('Symfony.com');
208
        $project->setDescription('Symfony.com website');
209
        $project->setLink('https://github.com/symfony/symfony-marketing');
210
        $project->setRepository('https://github.com/symfony/symfony-marketing');
211
        $project->setSlug('symfony-marketing');
212
        $projects[] = $project;
213
214
        $project = new Project();
215
        $project->setTitle('Sonata Project');
216
        $project->setDescription('Prevod projekta Sonata Project');
217
        $project->setLink('https://github.com/sonata-project');
218
        $project->setRepository('https://github.com/sonata-project');
219
        $project->setSlug('sonata-project');
220
        $projects[] = $project;
221
222
        $project = new Project();
223
        $project->setTitle('EasyAdminBundle');
224
        $project->setDescription('Prevod Symfony paketa EasyAdminBundle');
225
        $project->setLink('https://github.com/javiereguiluz/EasyAdminBundle');
226
        $project->setRepository('https://github.com/javiereguiluz/EasyAdminBundle');
227
        $project->setSlug('easy-admin-bundle');
228
        $projects[] = $project;
229
230
        $project = new Project();
231
        $project->setTitle('PHP: The Right Way');
232
        $project->setDescription('An easy-to-read, quick reference for PHP best practices, accepted coding standards, and links to authoritative tutorials around the Web');
233
        $project->setLink('http://sl.phptherightway.com');
234
        $project->setRepository('https://github.com/symfony-si/php-the-right-way');
235
        $project->setSlug('php-the-right-way');
236
        $projects[] = $project;
237
238
        $project = new Project();
239
        $project->setTitle('PHP FIG');
240
        $project->setDescription('PHP Standards Recommendations');
241
        $project->setLink('http://php-fig.org');
242
        $project->setRepository('https://github.com/php-fig/fig-standards');
243
        $project->setSlug('php-fig-standards');
244
        $projects[] = $project;
245
246
        $project = new Project();
247
        $project->setTitle('Magento');
248
        $project->setDescription('Magento 1.x Translation');
249
        $project->setLink('http://magento.com/');
250
        $project->setRepository('https://github.com/symfony-si/magento1-sl-si');
251
        $project->setSlug('magento1');
252
        $projects[] = $project;
253
254
        $project = new Project();
255
        $project->setTitle('Magento 2');
256
        $project->setDescription('Magento 2.x Translation');
257
        $project->setLink('http://magento.com/');
258
        $project->setRepository('https://github.com/symfony-si/magento2-sl_si');
259
        $project->setSlug('magento2');
260
        $projects[] = $project;
261
262
        $project = new Project();
263
        $project->setTitle('Semver.org');
264
        $project->setDescription('Semantic Versions');
265
        $project->setLink('http://semver.org/lang/sl');
266
        $project->setRepository('https://github.com/mojombo/semver.org');
267
        $project->setSlug('semantic-versioning');
268
        $projects[] = $project;
269
270
        $project = new Project();
271
        $project->setTitle('The PHP League');
272
        $project->setDescription('Slovenski prevod strani PHP lige paketov');
273
        $project->setLink('http://thephpleague.com/sl/');
274
        $project->setRepository('https://github.com/thephpleague/thephpleague.github.io');
275
        $project->setSlug('the-php-league');
276
        $projects[] = $project;
277
278
        $project = new Project();
279
        $project->setTitle('Yii framework');
280
        $project->setDescription('Slovenski prevod ogrodja Yii 2');
281
        $project->setLink('https://github.com/yiisoft/yii2');
282
        $project->setRepository('https://github.com/yiisoft/yii2');
283
        $project->setSlug('the-php-league');
284
        $projects[] = $project;
285
286
        $project = new Project();
287
        $project->setTitle('Progit');
288
        $project->setDescription('Slovenski prevod knjige progit');
289
        $project->setLink('http://git-scm.com/book/sl');
290
        $project->setRepository('https://github.com/progit/progit2-sl');
291
        $project->setSlug('progit');
292
        $projects[] = $project;
293
294
        $project = new Project();
295
        $project->setTitle('Zend Framework 2');
296
        $project->setDescription('Slovenian translation of Zend Framework 2');
297
        $project->setLink('https://github.com/zendframework/zf2');
298
        $project->setRepository('https://github.com/zendframework/zf2');
299
        $project->setSlug('zend-framework-2');
300
        $projects[] = $project;
301
302
        return $this->render(
303
            'default/ecosystem.html.twig',
304
            ['projects' => $projects]
305
        );
306
    }
307
308
    /**
309
     * @Route("/code-of-conduct", name="conduct")
310
     * @Cache(expires="tomorrow", public=true)
311
     *
312
     * @return Response
313
     */
314
    public function conductAction()
315
    {
316
        $file = $this->get('kernel')->getRootDir().'/../vendor/symfony-si/conduct/README.md';
317
        $content = (file_exists($file)) ? file_get_contents($file) : '<h1>Symfony.si Code of Conduct</h1>';
318
        $parser = new Parser();
319
        $document = $parser->parse($content);
320
321
        return $this->render('default/conduct.html.twig', ['content' => $document->getContent()]);
322
    }
323
}
324