-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathredirector.php
More file actions
156 lines (137 loc) · 3.06 KB
/
Copy pathredirector.php
File metadata and controls
156 lines (137 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php namespace Feather\Components\Support;
use URL;
use URI;
use Input;
use Bundle;
use Request;
use Redirect;
use Feather\Auth;
use Feather\Config;
use Laravel\Messages;
class Redirector extends Redirect {
/**
* Add an alert to the session flash data.
*
* @param string $type
* @param string $key
* @param array $replacements
* @return object
*/
public function with_alert($type, $key, $replacements = array())
{
return $this->with('alert', array('type' => $type, 'message' => __($key, $replacements)));
}
/**
* Create a redirect response with the query string appended.
*
* @param string $url
* @return object
*/
public function with_query($url)
{
$url = URL::to($this->pattern($url));
if($query = urldecode(Request::getQueryString()))
{
$url = "{$url}?{$query}";
}
return $this->to($url);
}
/**
* Create a redirect response to the current page.
*
* @return object
*/
public function to_self()
{
return $this->with_query(URI::current());
}
/**
* Create a redirect response to the previous page.
*
* @param string $default
* @return object
*/
public function to_previous($default = null)
{
return $this->to(Input::has('return') ? Input::get('return') : $this->pattern($default));
}
/**
* Create a redirect response after a logout.
*
* @return object
*/
public function after_logout()
{
return $this->for_auth(Config::get('feather: db.auth.logout_url'));
}
/**
* Create a redirect response before a registration.
*
* @return object
*/
public function before_register()
{
return $this->for_auth(Config::get('feather: db.auth.register_url'));
}
/**
* Create a redirect response before a login.
*
* @return object
*/
public function before_login()
{
return $this->for_auth(Config::get('feather: db.auth.login_url'));
}
/**
* Create a redirect response to an authentication page.
*
* @param string $url
* @return object
*/
protected function for_auth($url)
{
$replace = array(
'{feather}' => Bundle::option('feather', 'handles'),
'{current}' => URL::to(Input::has('return') ? Input::get('return') : URI::current()),
'{token}' => Auth::online() ? Auth::user()->authenticator_token : null
);
if(Config::get('feather: db.auth.driver') == 'internal')
{
$url = URL::to_route('feather');
}
else
{
$url = str_replace(array_keys($replace), array_values($replace), $url);
}
return $this->to($url);
}
/**
* Builds a URL based on defined patterns.
*
* @param string $url
* @return string
*/
protected function pattern($url)
{
if(starts_with($url, 'route: '))
{
return URL::to_route(substr($url, 7));
}
elseif(starts_with($url, 'action: '))
{
return URL::to_action(substr($url, 8));
}
return $url;
}
/**
* Flash a Validator's errors to the session data.
*
* @param object|string $container
* @return object
*/
public function with_errors($container)
{
$errors = !($container instanceof Messages) ? new Messages(array($container)) : $container;
return $this->with('errors', $errors);
}
}