Test Setup Failed
Branch v1 (b1dea4)
by Andrew
03:56
created

CpNavController::actionResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * ImageOptimize plugin for Craft CMS 3.x
4
 *
5
 * Automatically optimize images after they've been transformed
6
 *
7
 * @link      https://nystudio107.com
8
 * @copyright Copyright (c) 2017 nystudio107
9
 */
10
11
namespace nystudio107\imageoptimize\controllers;
12
13
use nystudio107\imageoptimize\ImageOptimize;
14
15
use Craft;
16
use craft\web\Controller;
17
18
use yii\web\Response;
19
20
/**
21
 * @author    nystudio107
22
 * @package   Retour
23
 * @since     3.0.0
24
 */
25
class CpNavController extends Controller
26
{
27
    // Constants
28
    // =========================================================================
29
30
    // Protected Properties
31
    // =========================================================================
32
33
    /**
34
     * @var    bool|array Allows anonymous access to this controller's actions.
35
     *         The actions must be in 'kebab-case'
36
     * @access protected
37
     */
38
    protected $allowAnonymous = [
39
        'resource'
40
    ];
41
42
    // Public Methods
43
    // =========================================================================
44
45
    /**
46
     * Make webpack async bundle loading work out of published AssetBundles
47
     *
48
     * @param string $resourceType
49
     * @param string $fileName
50
     *
51
     * @return Response
52
     */
53
    public function actionResource(string $resourceType = '', string $fileName = ''): Response
54
    {
55
        $baseAssetsUrl = Craft::$app->assetManager->getPublishedUrl(
56
            '@nystudio107/imageoptimize/assetbundles/imageoptimize/dist',
57
            true
58
        );
59
        $url = "{$baseAssetsUrl}/{$resourceType}/{$fileName}";
60
61
        return $this->redirect($url);
62
    }
63
}
64