|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Superdesk Web Publisher Core Bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2015 Sourcefabric z.u. and contributors. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please see the |
|
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright 2015 Sourcefabric z.ú |
|
12
|
|
|
* @license http://www.superdesk.org/license |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace SWP\Bundle\CoreBundle\Controller; |
|
16
|
|
|
|
|
17
|
|
|
use Hoa\File\Read; |
|
18
|
|
|
use Hoa\Mime\Mime; |
|
19
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
20
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
21
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
23
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
|
24
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
25
|
|
|
|
|
26
|
|
|
class StaticThemeAssetsController extends Controller |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Directory with assets inside theme. |
|
30
|
|
|
*/ |
|
31
|
|
|
const ASSETS_DIRECTORY = 'public'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @Route("/{fileName}.{fileExtension}", name="static_theme_assets_root", requirements={ |
|
35
|
|
|
* "fileName": "sw|manifest" |
|
36
|
|
|
* }) |
|
37
|
|
|
* @Method("GET") |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function rootAction($fileName, $fileExtension) |
|
40
|
|
|
{ |
|
41
|
1 |
|
$theme = $this->get('sylius.context.theme')->getTheme(); |
|
42
|
1 |
|
$filePath = $theme->getPath().'/'.self::ASSETS_DIRECTORY.'/'.$fileName.'.'.$fileExtension; |
|
43
|
1 |
|
if (null !== $response = $this->handleFileLoading($filePath)) { |
|
44
|
1 |
|
return $response; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
throw new NotFoundHttpException('Page was not found.'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @Route("/public/{filePath}", name="static_theme_assets_public", requirements={"filePath"=".+"}) |
|
52
|
|
|
* @Method("GET") |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function publicAction($filePath) |
|
55
|
|
|
{ |
|
56
|
1 |
|
$theme = $this->get('sylius.context.theme')->getTheme(); |
|
57
|
1 |
|
$filePath = $theme->getPath().'/'.self::ASSETS_DIRECTORY.'/'.$filePath; |
|
58
|
1 |
|
if (null !== $response = $this->handleFileLoading($filePath, basename($filePath))) { |
|
|
|
|
|
|
59
|
1 |
|
return $response; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
throw new NotFoundHttpException('File was not found.', null, 404); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param $filePath |
|
67
|
|
|
* |
|
68
|
|
|
* @return Response |
|
69
|
|
|
*/ |
|
70
|
2 |
|
private function handleFileLoading($filePath) |
|
71
|
|
|
{ |
|
72
|
2 |
|
if (file_exists($filePath)) { |
|
73
|
2 |
|
$response = new Response(file_get_contents($filePath)); |
|
74
|
2 |
|
$disposition = $response->headers->makeDisposition( |
|
75
|
2 |
|
ResponseHeaderBag::DISPOSITION_INLINE, |
|
76
|
|
|
basename($filePath) |
|
77
|
|
|
); |
|
78
|
2 |
|
$response->headers->set('Content-Disposition', $disposition); |
|
79
|
2 |
|
$type = new Mime(new Read($filePath)); |
|
80
|
2 |
|
$mime = str_replace('/x-', '/', Mime::getMimeFromExtension($type->getExtension())); |
|
81
|
2 |
|
$response->headers->set('Content-Type', $mime); |
|
82
|
2 |
|
$response->setStatusCode(Response::HTTP_OK); |
|
83
|
|
|
|
|
84
|
2 |
|
return $response; |
|
85
|
|
|
} |
|
86
|
1 |
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.