routes.php ➔ verificar_dominio()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 50
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 31
nc 5
nop 0
dl 0
loc 50
rs 8.6315
c 0
b 0
f 0
1
<?php
2
/**
3
 * Routes configuration
4
 *
5
 * In this file, you set up routes to your controllers and their actions.
6
 * Routes are very important mechanism that allows you to freely connect
7
 * different URLs to chosen controllers and their actions (functions).
8
 *
9
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
10
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11
 *
12
 * Licensed under The MIT License
13
 * For full copyright and license information, please see the LICENSE.txt
14
 * Redistributions of files must retain the above copyright notice.
15
 *
16
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
17
 * @link          http://cakephp.org CakePHP(tm) Project
18
 * @package       app.Config
19
 * @since         CakePHP(tm) v 0.2.9
20
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
21
 */
22
/**
23
 * Here, we are connecting '/' (base path) to controller called 'Pages',
24
 * its action called 'display', and we pass a param to select the view file
25
 * to use (in this case, /app/View/Pages/home.ctp)...
26
 */
27
	//Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
28
/**
29
 * ...and connect the rest of 'Pages' controller's URLs.
30
 */
31
	//Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
32
	
33
	$dominio = verificar_dominio();
34
35
	if ($dominio['is_winners']) {
36
		Router::connect('/', array('controller' => 'home', 'action' => 'index'));
37
	} else {
38
		Router::connect('/', array('controller' => $dominio['controller'], 'action' => $dominio['funcao']));
39
	}
40
41
	$caminho = APP . 'Config/routesshop.php';
42
	
43
	Router::connect('/servicos', array('controller' => 'home', 'action', 'servicos'));
44
	Router::connect('/linha-do-tempo-winners-opensource', array('controller' => 'home', 'action' => 'timeline'));
45
	Router::connect('/canal-para-desenvolvedores-winners', array('controller' => 'home', 'action' => 'developers'));
46
	Router::connect('/clientes-erp-ecommerce-software-sob-medida-winners', array('controller' => 'home', 'action' => 'cases'));
47
	Router::connect('/quero-saber-como-funciona-winners-opensource', array('controller' => 'home', 'action' => 'contact'));
48
	
49
	require($caminho);
50
/**
51
 * Load all plugin routes. See the CakePlugin documentation on
52
 * how to customize the loading of plugin routes.
53
 */
54
	CakePlugin::routes();
55
56
/**
57
 * Load the CakePHP default routes. Only remove this if you do not want to use
58
 * the built-in default routes.
59
 */
60
	require CAKE . 'Config' . DS . 'routes.php';
61
/**
62
 * Função para verificar se o dominio pentece ao site, caso não pertença redireciona ao site correto 
63
 */
64
	function verificar_dominio() {
0 ignored issues
show
Coding Style introduced by
verificar_dominio 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...
65
		$dominiosWinners = array (
66
			'winners.local',
67
			'blog.winnersdesenvolvimento.com.br',
68
			'ciawn.com.br',
69
			'www.ciawn.com.br',
70
			'api.ciawn.com.br',
71
			'winnersopensource.herokuapp.com'
72
		);
73
74
		$dominiosWinnersRedirect = array(
75
			'www.winnersdesenvolvimento.com.br',
76
			'winnersdesenvolvimento.com.br',
77
		);
78
79
		$varDominio = $_SERVER['SERVER_NAME'];
80
		
81
		if (array_search($varDominio, $dominiosWinnersRedirect) !== false || $varDominio == "ciawn.com.br") {
82
			header('Location: http://www.ciawn.com.br');
83
			exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function verificar_dominio() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
84
		}
85
86
		if (array_search($varDominio, $dominiosWinners) !== false) {
87
			$retorno['is_winners'] = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$retorno was never initialized. Although not strictly required by PHP, it is generally a good practice to add $retorno = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
88
89
			return $retorno;
90
		}
91
		
92
		if ($varDominio == "fastshipping.ciawn.com.br")
93
		{
94
			header('Location: https://fastshipping.ciawn.com.br');
95
			exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function verificar_dominio() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
96
		}
97
		
98
		$caminho = APP . 'Config/Domain/' . $varDominio . '.php';
99
		if (!file_exists($caminho))
100
		{
101
			$retorno['is_winners'] = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$retorno was never initialized. Although not strictly required by PHP, it is generally a good practice to add $retorno = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
102
			return $retorno;
103
		}
104
		
105
		require($caminho);
106
107
		$retorno['is_winners'] = false;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$retorno was never initialized. Although not strictly required by PHP, it is generally a good practice to add $retorno = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
108
		$retorno['id_usuario'] = $dominio['id_usuario'];
0 ignored issues
show
Bug introduced by
The variable $dominio does not exist. Did you mean $dominiosWinners?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
109
		$retorno['controller'] = $dominio['controller'];
0 ignored issues
show
Bug introduced by
The variable $dominio does not exist. Did you mean $dominiosWinners?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
110
		$retorno['funcao']	   = $dominio['funcao'];
0 ignored issues
show
Bug introduced by
The variable $dominio does not exist. Did you mean $dominiosWinners?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
111
112
		return $retorno;
113
	}