1+ <?php
2+ /**
3+ * Created by PhpStorm.
4+ * User: Bui
5+ * Date: 9/30/2015
6+ * Time: 1:36 PM
7+ */
8+
9+ namespace fproject \authclient ;
10+
11+ use Yii ;
12+ use yii \authclient \Collection ;
13+ use yii \base \Action ;
14+
15+ abstract class AuthLogoutActionBase extends Action
16+ {
17+ /**
18+ * @var callable PHP callback, which should be triggered before this action is run.
19+ * This callback should accept [[ClientInterface]] instance as an argument.
20+ * For example:
21+ *
22+ * ~~~
23+ * public function onBeforeLogout($client)
24+ * {
25+ * $attributes = $client->getUserAttributes();
26+ * // user login or signup comes here
27+ * }
28+ * ~~~
29+ *
30+ * If this callback returns [[Response]] instance, it will be used as action response,
31+ * otherwise redirection to [[successUrl]] will be performed.
32+ *
33+ */
34+ public $ beforeActionCallback ;
35+
36+ /**
37+ * @var callable PHP callback, which should be triggered after this action is run.
38+ * This callback should accept [[ClientInterface]] instance as an argument.
39+ * For example:
40+ *
41+ * ~~~
42+ * public function onAfterLogout($client)
43+ * {
44+ * $attributes = $client->getUserAttributes();
45+ * // user login or signup comes here
46+ * }
47+ * ~~~
48+ *
49+ * If this callback returns [[Response]] instance, it will be used as action response,
50+ * otherwise redirection to [[successUrl]] will be performed.
51+ *
52+ */
53+ public $ afterActionCallback ;
54+
55+ /**
56+ * @var string $clientCollection name of the auth client collection application component.
57+ * It should point to [[Collection]] instance.
58+ */
59+ public $ clientCollection = 'authClientCollection ' ;
60+
61+ /** @var string $authClientId the auth client ID*/
62+ public $ authClientId ;
63+
64+ /** @var OAuth2 $client */
65+ protected $ client ;
66+
67+ /**
68+ * @inheritdoc
69+ */
70+ public function run ()
71+ {
72+ /** @var Collection $collection */
73+ $ collection = Yii::$ app ->get ($ this ->clientCollection );
74+ $ this ->client = $ collection ->getClient ($ this ->authClientId );
75+ if (is_callable ($ this ->beforeActionCallback ))
76+ {
77+ call_user_func ($ this ->beforeActionCallback , $ this ->client );
78+ }
79+ }
80+ }
0 commit comments