SeoManager::pick()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.2888
c 0
b 0
f 0
cc 5
nc 16
nop 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2011 - 2014 Oleksandr Torosh (http://wezoom.net)
4
 * @author Oleksandr Torosh <[email protected]>
5
 */
6
7
namespace Seo\Plugin;
8
9
use Phalcon\Mvc\Router;
10
use Phalcon\Mvc\User\Plugin;
11
use Phalcon\Http\Request;
12
use Phalcon\Mvc\Dispatcher;
13
use Phalcon\Mvc\View;
14
use Seo\Model\Manager;
15
16
/**
17
 * Class SeoManagerPlugin
18
 * @package Seo\Plugin
19
 * @variable $matched_route \Seo\Model\Manager
20
 */
21
class SeoManager extends Plugin
22
{
23
24
    const CACHE_LIFETIME = 120;
25
26
    public function __construct(Dispatcher $dispatcher, Request $request, Router $router, View $view)
27
    {
28
        if ($view->getLayout() == 'admin') {
29
            return;
30
        }
31
32
        $match_url_entry = $this->matchingUrl($request->getURI());
33
        if ($match_url_entry) {
34
            $this->pick($match_url_entry);
35
        }
36
    }
37
38
    private function matchingUrl($url)
39
    {
40
        $urls = Manager::urls();
41
        if (array_key_exists($url, $urls)) {
42
            return $urls[$url];
43
        }
44
45
    }
46
47
    private function pick($entry)
48
    {
49
        $helper = $this->getDI()->get('helper');
0 ignored issues
show
Bug introduced by
The method get cannot be called on $this->getDI() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
50
        $view = $this->getDi()->get('view');
0 ignored issues
show
Bug introduced by
The method get cannot be called on $this->getDi() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
51
52
        if ($entry['head_title']) {
53
            $helper->title()->set($entry['head_title']);
54
        }
55
        if ($entry['meta_description']) {
56
            $helper->meta()->set('description', $entry['meta_description']);
57
        }
58
        if ($entry['meta_keywords']) {
59
            $helper->meta()->set('keywords', $entry['meta_keywords']);
60
        }
61
        if ($entry['seo_text']) {
62
            $view->seo_text = $entry['seo_text'];
63
        }
64
65
        $helper->meta()->set('seo-manager', 'matched');
66
    }
67
68
}