OpauthAuthenticator::get_name()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * Base authenticator for SilverStripe Opauth module.
5
 * @author Will Morgan <@willmorgan>
6
 * @author Dan Hensby <@dhensby>
7
 * @copyright Copyright (c) 2013, Better Brief LLP
8
 */
9
class OpauthAuthenticator extends MemberAuthenticator {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
11
	private static
12
		/**
13
		 * @var Opauth Persistent Opauth instance.
14
		 */
15
		$opauth;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $opauth.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
16
17
	/**
18
	 * get_enabled_strategies
19
	 * @return array Enabled strategies set in _config
20
	 */
21
	public static function get_enabled_strategies() {
22
		$strategyConfig = self::config()->opauth_settings['Strategy'];
23
		return array_keys($strategyConfig);
24
	}
25
26
	/**
27
	 * get_opauth_config
28
	 * @param array Any extra overrides
29
	 * @return array Config for use with Opauth
30
	 */
31
	public static function get_opauth_config($mergeConfig = array()) {
32
		$config = self::config();
33
		return array_merge(
34
			array(
35
				'path' => OpauthController::get_path(),
36
				'callback_url' => OpauthController::get_callback_path(),
37
			),
38
			$config->opauth_settings,
39
			$mergeConfig
40
		);
41
	}
42
43
	/**
44
	 * opauth
45
	 * @param boolean $autoRun Should Opauth auto run? Default: false
46
	 * @return Opauth The Opauth instance. Isn't it easy to typo this as Opeth?
47
	 */
48
	public static function opauth($autoRun = false, $config = array()) {
49
		if(!isset(self::$opauth)) {
50
			self::$opauth = new Opauth(self::get_opauth_config($config), $autoRun);
51
		}
52
		return self::$opauth;
53
	}
54
55
	/**
56
	 * get_strategy_segment
57
	 * Works around Opauth's weird URL scheme - GoogleStrategy => /google/
58
	 * @return string
59
	 */
60
	public static function get_strategy_segment($strategy) {
61
		return preg_replace('/(strategy)$/', '', strtolower($strategy));
62
	}
63
64
	/**
65
	 * @return OpauthLoginForm
66
	 */
67
	public static function get_login_form(Controller $controller) {
68
		return Injector::inst()->create('OpauthLoginForm', $controller, 'LoginForm');
69
	}
70
71
	/**
72
	 * Get the name of the authentication method
73
	 *
74
	 * @return string Returns the name of the authentication method.
75
	 */
76
	public static function get_name() {
77
		return _t('OpauthAuthenticator.TITLE', 'Social Login');
78
	}
79
80
}
81