Issues (257)

src/twigextensions/SeomaticTwigExtension.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * SEOmatic plugin for Craft CMS
4
 *
5
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
6
 * and flexible
7
 *
8
 * @link      https://nystudio107.com
9
 * @copyright Copyright (c) 2017 nystudio107
10
 */
11
12
namespace nystudio107\seomatic\twigextensions;
13
14
use Craft;
15
use nystudio107\seomatic\Node\Expression\EmptyCoalesceExpression;
16
use nystudio107\seomatic\Seomatic;
17
18
use nystudio107\seomatic\variables\SeomaticVariable;
19
20
use Twig\ExpressionParser;
0 ignored issues
show
The type Twig\ExpressionParser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Twig\Extension\AbstractExtension;
22
use Twig\Extension\GlobalsInterface;
23
24
use yii\base\InvalidConfigException;
25
26
/**
27
 * @author    nystudio107
28
 * @package   Seomatic
29
 * @since     3.0.0
30
 */
31
class SeomaticTwigExtension extends AbstractExtension implements GlobalsInterface
32
{
33
    /**
34
     * @inheritdoc
35
     */
36
    public function getGlobals(): array
37
    {
38
        $request = Craft::$app->getRequest();
39
        // Seomatic::$view->getIsRenderingPageTemplate() &&
40
        if (!Seomatic::$seomaticVariable && !Seomatic::$previewingMetaContainers) {
41
            // Create our variable and stash it in the plugin for global access
42
            Seomatic::$seomaticVariable = new SeomaticVariable();
43
            // Get the path for the current request
44
            $requestPath = '/';
45
            if (!$request->getIsConsoleRequest()) {
46
                try {
47
                    $requestPath = $request->getPathInfo();
48
                } catch (InvalidConfigException $e) {
49
                    Craft::error($e->getMessage(), __METHOD__);
50
                }
51
            }
52
            if (!$request->getIsCpRequest()) {
53
                // Load the meta containers for this page
54
                Seomatic::$plugin->metaContainers->loadMetaContainers($requestPath, null);
55
            } else {
56
                // If this is a CP request, load the bare minimum, which is the global container,
57
                // and re-init the SEOmatic variable to ensure it points to the new settings
58
                Seomatic::$plugin->metaContainers->loadGlobalMetaContainers();
59
                Seomatic::$seomaticVariable->init();
60
            }
61
        }
62
63
        return ['seomatic' => Seomatic::$seomaticVariable];
64
    }
65
66
    /**
67
     * Return our Twig Extension name
68
     *
69
     * @return string
70
     */
71
    public function getName(): string
72
    {
73
        return 'Seomatic';
74
    }
75
76
    /**
77
     * Return our Twig filters
78
     *
79
     * @return array
80
     */
81
    public function getFilters(): array
82
    {
83
        return [];
84
    }
85
86
    /**
87
     * Return our Twig functions
88
     *
89
     * @return array
90
     */
91
    public function getFunctions(): array
92
    {
93
        return [];
94
    }
95
96
    /**
97
     * @return array
98
     */
99
    public function getOperators(): array
100
    {
101
        return [
102
            // Unary operators
103
            [],
104
            // Binary operators
105
            [
106
                '???' => [
107
                    'precedence' => 300,
108
                    'class' => EmptyCoalesceExpression::class,
109
                    'associativity' => ExpressionParser::OPERATOR_RIGHT,
110
                ],
111
            ],
112
        ];
113
    }
114
}
115