nystudio107 /
craft-richvariables
| 1 | <?php |
||
| 2 | |||
| 3 | namespace nystudio107\richvariables\variables; |
||
| 4 | |||
| 5 | use nystudio107\richvariables\helpers\Manifest as ManifestHelper; |
||
| 6 | use nystudio107\richvariables\assetbundles\richvariables\RichVariablesAsset; |
||
| 7 | |||
| 8 | use Craft; |
||
| 9 | use craft\helpers\Template; |
||
| 10 | |||
| 11 | class ManifestVariable |
||
| 12 | { |
||
| 13 | // Protected Static Properties |
||
| 14 | // ========================================================================= |
||
| 15 | |||
| 16 | protected static $config = [ |
||
| 17 | // If `devMode` is on, use webpack-dev-server to all for HMR (hot module reloading) |
||
| 18 | 'useDevServer' => true, |
||
| 19 | // Manifest names |
||
| 20 | 'manifest' => [ |
||
| 21 | 'legacy' => 'manifest.json', |
||
| 22 | 'modern' => 'manifest.json', |
||
| 23 | ], |
||
| 24 | // Public server config |
||
| 25 | 'server' => [ |
||
| 26 | 'manifestPath' => '/', |
||
| 27 | 'publicPath' => '/', |
||
| 28 | ], |
||
| 29 | // webpack-dev-server config |
||
| 30 | 'devServer' => [ |
||
| 31 | 'manifestPath' => 'http://127.0.0.1:8080', |
||
| 32 | 'publicPath' => '/', |
||
| 33 | ], |
||
| 34 | ]; |
||
| 35 | |||
| 36 | // Public Methods |
||
| 37 | // ========================================================================= |
||
| 38 | |||
| 39 | /** |
||
| 40 | * ManifestVariable constructor. |
||
| 41 | */ |
||
| 42 | public function __construct() |
||
| 43 | { |
||
| 44 | ManifestHelper::invalidateCaches(); |
||
| 45 | $bundle = new RichVariablesAsset(); |
||
| 46 | $baseAssetsUrl = Craft::$app->assetManager->getPublishedUrl( |
||
| 47 | $bundle->sourcePath, |
||
| 48 | true |
||
|
0 ignored issues
–
show
|
|||
| 49 | ); |
||
| 50 | self::$config['server']['manifestPath'] = Craft::getAlias($bundle->sourcePath); |
||
| 51 | self::$config['server']['publicPath'] = $baseAssetsUrl; |
||
| 52 | $useDevServer = getenv('NYS_PLUGIN_DEVSERVER'); |
||
| 53 | if ($useDevServer !== false) { |
||
| 54 | self::$config['useDevServer'] = (bool)$useDevServer; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param string $moduleName |
||
| 60 | * @param bool $async |
||
| 61 | * @param null|array $config |
||
| 62 | * |
||
| 63 | * @return null|\Twig_Markup |
||
| 64 | * @throws \yii\web\NotFoundHttpException |
||
| 65 | */ |
||
| 66 | public function includeCssModule(string $moduleName, bool $async = false, $config = null) |
||
| 67 | { |
||
| 68 | return Template::raw( |
||
| 69 | ManifestHelper::getCssModuleTags(self::$config, $moduleName, $async) ?? '' |
||
| 70 | ); |
||
| 71 | } |
||
| 72 | |||
| 73 | |||
| 74 | /** |
||
| 75 | * Returns the uglified loadCSS rel=preload Polyfill as per: |
||
| 76 | * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example |
||
| 77 | * |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | public static function includeCssRelPreloadPolyfill(): string |
||
| 81 | { |
||
| 82 | return Template::raw( |
||
| 83 | ManifestHelper::getCssRelPreloadPolyfill() ?? '' |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param string $moduleName |
||
| 89 | * @param bool $async |
||
| 90 | * @param null|array $config |
||
| 91 | * |
||
| 92 | * @return null|\Twig_Markup |
||
| 93 | * @throws \yii\web\NotFoundHttpException |
||
| 94 | */ |
||
| 95 | public function includeJsModule(string $moduleName, bool $async = false, $config = null) |
||
| 96 | { |
||
| 97 | return Template::raw( |
||
| 98 | ManifestHelper::getJsModuleTags(self::$config, $moduleName, $async) ?? '' |
||
| 99 | ); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Return the URI to a module |
||
| 104 | * |
||
| 105 | * @param string $moduleName |
||
| 106 | * @param string $type |
||
| 107 | * @param null $config |
||
| 108 | * |
||
| 109 | * @return null|\Twig_Markup |
||
| 110 | * @throws \yii\web\NotFoundHttpException |
||
| 111 | */ |
||
| 112 | public function getModuleUri(string $moduleName, string $type = 'modern', $config = null) |
||
| 113 | { |
||
| 114 | return Template::raw( |
||
| 115 | ManifestHelper::getModule(self::$config, $moduleName, $type) ?? '' |
||
| 116 | ); |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Include the Safari 10.1 nomodule fix JavaScript |
||
| 121 | * |
||
| 122 | * @return \Twig_Markup |
||
| 123 | */ |
||
| 124 | public function includeSafariNomoduleFix() |
||
| 125 | { |
||
| 126 | return Template::raw( |
||
| 127 | ManifestHelper::getSafariNomoduleFix() ?? '' |
||
| 128 | ); |
||
| 129 | } |
||
| 130 | } |
||
| 131 |
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. Please note the @ignore annotation hint above.