BaseController::getDefaultLocale()   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 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Stinger Soft Platform package.
5
 *
6
 * (c) Oliver Kotte <[email protected]>
7
 * (c) Florian Meyer <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
namespace StingerSoft\PlatformBundle\Controller;
13
14
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15
use Symfony\Component\Stopwatch\Stopwatch;
16
use Symfony\Component\Translation\TranslatorInterface;
17
use Doctrine\Common\Persistence\ObjectRepository;
18
19
class BaseController extends Controller {
20
21
	/**
22
	 * Returns the default locale for the system
23
	 *
24
	 * @return string
25
	 */
26
	protected function getDefaultLocale() {
27
		return 'en';
28
	}
29
30
	/**
31
	 * Returns all available (i.e.
32
	 * configured) locales of the system
33
	 *
34
	 * @return string[]
35
	 */
36
	protected function getLocales() {
37
		return array(
38
			'en' 
39
		);
40
	}
41
42
	/**
43
	 * Proxy to use the transChoice method of the translator
44
	 *
45
	 * @see TranslatorInterface::transChoice()
46
	 *
47
	 * @param string $id        	
48
	 * @param int $number        	
49
	 * @param array $parameters        	
50
	 * @param string $domain        	
0 ignored issues
show
Documentation introduced by
Should the type for parameter $domain not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
51
	 * @param string $locale        	
0 ignored issues
show
Documentation introduced by
Should the type for parameter $locale not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
52
	 * @return string
53
	 */
54 View Code Duplication
	protected function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
		/**
56
		 *
57
		 * @var TranslatorInterface $translator
58
		 */
59
		$translator = $this->getTranslator();
60
		return $translator->transChoice($id, $number, $parameters, $domain, $locale);
61
	}
62
63
	/**
64
	 * Proxy to use the transChoice method of the translator
65
	 *
66
	 * @see TranslatorInterface::trans()
67
	 *
68
	 * @param string $id        	
69
	 * @param array $parameters        	
70
	 * @param string $domain        	
0 ignored issues
show
Documentation introduced by
Should the type for parameter $domain not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
71
	 * @param string $locale        	
0 ignored issues
show
Documentation introduced by
Should the type for parameter $locale not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
72
	 * @return string
73
	 */
74 View Code Duplication
	protected function trans($id, array $parameters = array(), $domain = null, $locale = null) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
		/**
76
		 *
77
		 * @var TranslatorInterface $translator
78
		 */
79
		$translator = $this->getTranslator();
80
		return $translator->trans($id, $parameters, $domain, $locale);
81
	}
82
83
	/**
84
	 * Returns the translator service
85
	 *
86
	 * @return TranslatorInterface
87
	 */
88
	protected function getTranslator() {
89
		return $this->get('translator');
90
	}
91
92
	/**
93
	 * Returns the paginator service
94
	 *
95
	 * @return \Knp\Component\Pager\PaginatorInterface
96
	 */
97
	protected function getPaginator() {
98
		return $this->get('knp_paginator');
99
	}
100
101
	/**
102
	 * Returns the stopwatch service if available
103
	 *
104
	 * @return Stopwatch|NULL
0 ignored issues
show
Documentation introduced by
Should the return type not be object|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
105
	 */
106
	protected function getStopWatch() {
107
		if($this->has('debug.stopwatch')) {
108
			return $this->get('debug.stopwatch');
109
		}
110
		return null;
111
	}
112
113
	/**
114
	 * Checks whether the current user has the specified role or not
115
	 *
116
	 * @param string $role        	
117
	 * @throws \LogicException
118
	 * @return boolean
119
	 */
120
	protected function hasRole($role) {
121
		if(!$this->container->has('security.authorization_checker')) {
122
			throw new \LogicException('The SecurityBundle is not registered in your application.');
123
		}
124
		return false !== $this->get('security.authorization_checker')->isGranted($role);
125
	}
126
127
	/**
128
	 * Returns the repository for the given clazz
129
	 * 
130
	 * @param string $class
131
	 * @return ObjectRepository
132
	 */
133
	protected function getRepository($class) {
134
		return $this->getDoctrine()->getManagerForClass($class)->getRepository($class);
135
	}
136
}