Completed
Push — master ( 3abd9e...be2f2e )
by Eric
03:05
created

Concrete5::getPost()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
1
<?php
2
/**
3
 * Jaeger
4
 *
5
 * @copyright	Copyright (c) 2015-2016, mithra62
6
 * @link		http://jaeger-app.com
7
 * @version		1.0
8
 * @filesource 	./Platforms/Concrete5.php
9
 */
10
namespace JaegerApp\Platforms;
11
12
use JaegerApp\Platforms\AbstractPlatform;
13
14
/**
15
 * Jaeger - Concrete5 Platform Object
16
 *
17
 * The bridge between mithra62 code and Concrete5 specific logic
18
 *
19
 * @package Platforms\Concrete5
20
 * @author Eric Lamb <[email protected]>
21
 */
22
class Concrete5 extends AbstractPlatform
23
{
24
    /**
25
     * The Concrete5 App object
26
     * @var \Concrete\Core\Support\Facade\Application
27
     */
28
    private $app = null;
29
    
30
    /**
31
     * (non-PHPdoc)
32
     * @see \mithra62\Platforms\AbstractPlatform::getDbCredentials()
33
     */
34
    public function getDbCredentials()
35
    {
36
        $database_config = \Config::get('database');
37
        $database_config = $database_config['connections'][$database_config['default-connection']];
38
        
39
        return array(
40
            'user' => $database_config['username'],
41
            'password' => $database_config['password'],
42
            'database' => $database_config['database'],
43
            'host' => $database_config['server'],
44
            'prefix' => '',
45
            'settings_table_name' => 'backup_pro_settings'
46
        );
47
    }
48
    
49
    /**
50
     * (non-PHPdoc)
51
     * @see \mithra62\Platforms\AbstractPlatform::getEmailConfig()
52
     */
53
    public function getEmailConfig()
54
    {
55
        if(!\Config::get('concrete.email.enabled')) {
56
            throw new Exception('Concrete5 email is disabled... you have to enable that for email to function');
57
        }
58
        
59
        $email = \Config::get('concrete.mail');
60
        $this->email_config = array();
0 ignored issues
show
Bug introduced by
The property email_config cannot be accessed from this context as it is declared private in class JaegerApp\Platforms\AbstractPlatform.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
61
        $this->email_config['type'] = $email['method'];
0 ignored issues
show
Bug introduced by
The property email_config cannot be accessed from this context as it is declared private in class JaegerApp\Platforms\AbstractPlatform.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
62
        $this->email_config['port'] = $email['methods']['smtp']['port'];
0 ignored issues
show
Bug introduced by
The property email_config cannot be accessed from this context as it is declared private in class JaegerApp\Platforms\AbstractPlatform.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
63
        if ($email['method'] == 'smtp') {
64
            $this->email_config['smtp_options']['host'] = $email['methods']['smtp']['server'];
0 ignored issues
show
Bug introduced by
The property email_config cannot be accessed from this context as it is declared private in class JaegerApp\Platforms\AbstractPlatform.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
65
            $this->email_config['smtp_options']['connection_config']['username'] = $email['methods']['smtp']['username'];
0 ignored issues
show
Bug introduced by
The property email_config cannot be accessed from this context as it is declared private in class JaegerApp\Platforms\AbstractPlatform.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
66
            $this->email_config['smtp_options']['connection_config']['password'] = $email['methods']['smtp']['password'];
0 ignored issues
show
Bug introduced by
The property email_config cannot be accessed from this context as it is declared private in class JaegerApp\Platforms\AbstractPlatform.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
67
            $this->email_config['smtp_options']['port'] = $email['methods']['smtp']['port'];
0 ignored issues
show
Bug introduced by
The property email_config cannot be accessed from this context as it is declared private in class JaegerApp\Platforms\AbstractPlatform.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
68
        }
69
        
70
        $this->email_config['sender_name'] = $this->getSiteName();
0 ignored issues
show
Bug introduced by
The property email_config cannot be accessed from this context as it is declared private in class JaegerApp\Platforms\AbstractPlatform.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
71
        $this->email_config['from_email'] = \Config::get('concrete.email.default.address');
0 ignored issues
show
Bug introduced by
The property email_config cannot be accessed from this context as it is declared private in class JaegerApp\Platforms\AbstractPlatform.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
72
        return $this->email_config;        
0 ignored issues
show
Bug introduced by
The property email_config cannot be accessed from this context as it is declared private in class JaegerApp\Platforms\AbstractPlatform.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
73
    }
74
    
75
    /**
76
     * (non-PHPdoc)
77
     * @see \mithra62\Platforms\AbstractPlatform::getCurrentUrl()
78
     */
79
    public function getCurrentUrl()
0 ignored issues
show
Coding Style introduced by
getCurrentUrl uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
80
    {
81
        return $_SERVER["REQUEST_URI"];
82
    }
83
    
84
    /**
85
     * (non-PHPdoc)
86
     * @see \mithra62\Platforms\AbstractPlatform::getSiteName()
87
     */
88
    public function getSiteName()
89
    {
90
        return \Config::get('concrete.site');
91
    }
92
    
93
    /**
94
     * (non-PHPdoc)
95
     * @see \mithra62\Platforms\AbstractPlatform::getTimezone()
96
     */
97
    public function getTimezone()
98
    {
99
        return \Config::get('app.timezone');
100
    }
101
    
102
    /**
103
     * (non-PHPdoc)
104
     * @see \mithra62\Platforms\AbstractPlatform::getSiteUrl()
105
     */
106
    public function getSiteUrl()
107
    {
108
        $app = $this->getApp(); 
109
        return (string)rtrim($app->make('url/canonical'), '/');
110
    }
111
    
112
    /**
113
     * (non-PHPdoc)
114
     * @see \mithra62\Platforms\AbstractPlatform::getEncryptionKey()
115
     */
116
    public function getEncryptionKey()
117
    {
118
        return \Config::get('concrete.security.token.encryption');
119
    }
120
    
121
    /**
122
     * (non-PHPdoc)
123
     * @see \mithra62\Platforms\AbstractPlatform::getConfigOverrides()
124
     */
125
    public function getConfigOverrides()
126
    {
127
        $config = \Config::get('backup_pro.overrides');
128
        if( is_array($config) ) {
129
            return $config;
130
        }
131
        
132
        return array();
133
    }
134
    
135
    /**
136
     * (non-PHPdoc)
137
     * @see \mithra62\Platforms\AbstractPlatform::redirect()
138
     */
139
    public function redirect($url)
140
    {
141
        return \Concrete\Core\Routing\Redirect::url($url);
142
    }
143
    
144
    /**
145
     * (non-PHPdoc)
146
     * 
147
     * @see \mithra62\Platforms\AbstractPlatform::getPost()
148
     */
149
    public function getPost($key, $default = false)
0 ignored issues
show
Coding Style introduced by
getPost uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
getPost uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
150
    {
151
        if (isset($_POST[$key])) {
152
            return $_POST[$key];
153
        } elseif (isset($_GET[$key])) {
154
            return $_GET[$key];
155
        }
156
        
157
        return $default;
158
    }
159
    
160
    /**
161
     * Returns an instance of the Concrete5 app object
162
     * @return \Concrete\Core\Support\Facade\Application
163
     */
164
    private function getApp()
165
    {
166
        if( is_null($this->app) ) {
167
            $this->app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
168
        }
169
        
170
        return $this->app;
171
    }
172
    
173
}