@@ -4,70 +4,70 @@ |
||
4 | 4 | |
5 | 5 | class ReportsTableSeeder extends Seeder |
6 | 6 | { |
7 | - /** |
|
8 | - * Run the database seeds. |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function run() |
|
13 | - { |
|
14 | - /** |
|
15 | - * Insert the permissions related to settings table. |
|
16 | - */ |
|
17 | - DB::table('permissions')->insert( |
|
18 | - [ |
|
19 | - /** |
|
20 | - * Reporting model permissions. |
|
21 | - */ |
|
22 | - [ |
|
23 | - 'name' => 'find', |
|
24 | - 'model' => 'reports', |
|
25 | - 'created_at' => \DB::raw('NOW()'), |
|
26 | - 'updated_at' => \DB::raw('NOW()') |
|
27 | - ], |
|
28 | - [ |
|
29 | - 'name' => 'search', |
|
30 | - 'model' => 'reports', |
|
31 | - 'created_at' => \DB::raw('NOW()'), |
|
32 | - 'updated_at' => \DB::raw('NOW()') |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'name' => 'list', |
|
36 | - 'model' => 'reports', |
|
37 | - 'created_at' => \DB::raw('NOW()'), |
|
38 | - 'updated_at' => \DB::raw('NOW()') |
|
39 | - ], |
|
40 | - [ |
|
41 | - 'name' => 'findby', |
|
42 | - 'model' => 'reports', |
|
43 | - 'created_at' => \DB::raw('NOW()'), |
|
44 | - 'updated_at' => \DB::raw('NOW()') |
|
45 | - ], |
|
46 | - [ |
|
47 | - 'name' => 'first', |
|
48 | - 'model' => 'reports', |
|
49 | - 'created_at' => \DB::raw('NOW()'), |
|
50 | - 'updated_at' => \DB::raw('NOW()') |
|
51 | - ], |
|
52 | - [ |
|
53 | - 'name' => 'paginate', |
|
54 | - 'model' => 'reports', |
|
55 | - 'created_at' => \DB::raw('NOW()'), |
|
56 | - 'updated_at' => \DB::raw('NOW()') |
|
57 | - ], |
|
58 | - [ |
|
59 | - 'name' => 'paginateby', |
|
60 | - 'model' => 'reports', |
|
61 | - 'created_at' => \DB::raw('NOW()'), |
|
62 | - 'updated_at' => \DB::raw('NOW()') |
|
63 | - ], |
|
64 | - [ |
|
65 | - 'name' => 'admin_count', |
|
66 | - 'model' => 'reports', |
|
67 | - 'created_at' => \DB::raw('NOW()'), |
|
68 | - 'updated_at' => \DB::raw('NOW()') |
|
69 | - ] |
|
70 | - ] |
|
71 | - ); |
|
72 | - } |
|
7 | + /** |
|
8 | + * Run the database seeds. |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function run() |
|
13 | + { |
|
14 | + /** |
|
15 | + * Insert the permissions related to settings table. |
|
16 | + */ |
|
17 | + DB::table('permissions')->insert( |
|
18 | + [ |
|
19 | + /** |
|
20 | + * Reporting model permissions. |
|
21 | + */ |
|
22 | + [ |
|
23 | + 'name' => 'find', |
|
24 | + 'model' => 'reports', |
|
25 | + 'created_at' => \DB::raw('NOW()'), |
|
26 | + 'updated_at' => \DB::raw('NOW()') |
|
27 | + ], |
|
28 | + [ |
|
29 | + 'name' => 'search', |
|
30 | + 'model' => 'reports', |
|
31 | + 'created_at' => \DB::raw('NOW()'), |
|
32 | + 'updated_at' => \DB::raw('NOW()') |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'name' => 'list', |
|
36 | + 'model' => 'reports', |
|
37 | + 'created_at' => \DB::raw('NOW()'), |
|
38 | + 'updated_at' => \DB::raw('NOW()') |
|
39 | + ], |
|
40 | + [ |
|
41 | + 'name' => 'findby', |
|
42 | + 'model' => 'reports', |
|
43 | + 'created_at' => \DB::raw('NOW()'), |
|
44 | + 'updated_at' => \DB::raw('NOW()') |
|
45 | + ], |
|
46 | + [ |
|
47 | + 'name' => 'first', |
|
48 | + 'model' => 'reports', |
|
49 | + 'created_at' => \DB::raw('NOW()'), |
|
50 | + 'updated_at' => \DB::raw('NOW()') |
|
51 | + ], |
|
52 | + [ |
|
53 | + 'name' => 'paginate', |
|
54 | + 'model' => 'reports', |
|
55 | + 'created_at' => \DB::raw('NOW()'), |
|
56 | + 'updated_at' => \DB::raw('NOW()') |
|
57 | + ], |
|
58 | + [ |
|
59 | + 'name' => 'paginateby', |
|
60 | + 'model' => 'reports', |
|
61 | + 'created_at' => \DB::raw('NOW()'), |
|
62 | + 'updated_at' => \DB::raw('NOW()') |
|
63 | + ], |
|
64 | + [ |
|
65 | + 'name' => 'admin_count', |
|
66 | + 'model' => 'reports', |
|
67 | + 'created_at' => \DB::raw('NOW()'), |
|
68 | + 'updated_at' => \DB::raw('NOW()') |
|
69 | + ] |
|
70 | + ] |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | } |
@@ -4,19 +4,19 @@ discard block |
||
4 | 4 | |
5 | 5 | class AssignRelationsSeeder extends Seeder |
6 | 6 | { |
7 | - /** |
|
8 | - * Run the database seeds. |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function run() |
|
13 | - { |
|
14 | - /** |
|
7 | + /** |
|
8 | + * Run the database seeds. |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function run() |
|
13 | + { |
|
14 | + /** |
|
15 | 15 | * Assign the permissions to the admin group. |
16 | 16 | */ |
17 | - $adminGroupId = DB::table('groups')->whereIn('name', 'admin')->select('id')->first()->id; |
|
18 | - DB::table('permissions')->whereIn('model', ['reports'])->each(function ($permission) use ($adminGroupId) { |
|
19 | - DB::table('groups_permissions')->insert( |
|
17 | + $adminGroupId = DB::table('groups')->whereIn('name', 'admin')->select('id')->first()->id; |
|
18 | + DB::table('permissions')->whereIn('model', ['reports'])->each(function ($permission) use ($adminGroupId) { |
|
19 | + DB::table('groups_permissions')->insert( |
|
20 | 20 | [ |
21 | 21 | 'permission_id' => $permission->id, |
22 | 22 | 'group_id' => $adminGroupId, |
@@ -24,6 +24,6 @@ discard block |
||
24 | 24 | 'updated_at' => \DB::raw('NOW()') |
25 | 25 | ] |
26 | 26 | ); |
27 | - }); |
|
28 | - } |
|
27 | + }); |
|
28 | + } |
|
29 | 29 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | * Assign the permissions to the admin group. |
16 | 16 | */ |
17 | 17 | $adminGroupId = DB::table('groups')->whereIn('name', 'admin')->select('id')->first()->id; |
18 | - DB::table('permissions')->whereIn('model', ['reports'])->each(function ($permission) use ($adminGroupId) { |
|
18 | + DB::table('permissions')->whereIn('model', ['reports'])->each(function($permission) use ($adminGroupId) { |
|
19 | 19 | DB::table('groups_permissions')->insert( |
20 | 20 | [ |
21 | 21 | 'permission_id' => $permission->id, |
@@ -4,23 +4,23 @@ |
||
4 | 4 | |
5 | 5 | class ClearDataSeeder extends Seeder |
6 | 6 | { |
7 | - /** |
|
8 | - * Run the database seeds. |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function run() |
|
13 | - { |
|
14 | - $adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id; |
|
15 | - $adminUserId = DB::table('users')->where('email', '[email protected]')->first()->id; |
|
16 | - $permissions = DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups']); |
|
7 | + /** |
|
8 | + * Run the database seeds. |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function run() |
|
13 | + { |
|
14 | + $adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id; |
|
15 | + $adminUserId = DB::table('users')->where('email', '[email protected]')->first()->id; |
|
16 | + $permissions = DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups']); |
|
17 | 17 | |
18 | - DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
19 | - DB::table('users_groups')->where('user_id', $adminUserId)->where('group_id', $adminGroupId)->delete(); |
|
18 | + DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
19 | + DB::table('users_groups')->where('user_id', $adminUserId)->where('group_id', $adminGroupId)->delete(); |
|
20 | 20 | |
21 | - DB::table('users')->where('email', '[email protected]')->delete(); |
|
22 | - DB::table('groups')->where('name', 'Admin')->delete(); |
|
21 | + DB::table('users')->where('email', '[email protected]')->delete(); |
|
22 | + DB::table('groups')->where('name', 'Admin')->delete(); |
|
23 | 23 | |
24 | - $permissions->delete(); |
|
25 | - } |
|
24 | + $permissions->delete(); |
|
25 | + } |
|
26 | 26 | } |
@@ -4,17 +4,17 @@ |
||
4 | 4 | |
5 | 5 | class DatabaseSeeder extends Seeder |
6 | 6 | { |
7 | - /** |
|
8 | - * Run the database seeds. |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function run() |
|
13 | - { |
|
14 | - $this->call(ClearDataSeeder::class); |
|
15 | - $this->call(UsersTableSeeder::class); |
|
16 | - $this->call(GroupsTableSeeder::class); |
|
17 | - $this->call(PermissionsTableSeeder::class); |
|
18 | - $this->call(AssignRelationsSeeder::class); |
|
19 | - } |
|
7 | + /** |
|
8 | + * Run the database seeds. |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function run() |
|
13 | + { |
|
14 | + $this->call(ClearDataSeeder::class); |
|
15 | + $this->call(UsersTableSeeder::class); |
|
16 | + $this->call(GroupsTableSeeder::class); |
|
17 | + $this->call(PermissionsTableSeeder::class); |
|
18 | + $this->call(AssignRelationsSeeder::class); |
|
19 | + } |
|
20 | 20 | } |
@@ -4,125 +4,125 @@ |
||
4 | 4 | |
5 | 5 | class UsersTableSeeder extends Seeder |
6 | 6 | { |
7 | - /** |
|
8 | - * Run the database seeds. |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function run() |
|
13 | - { |
|
14 | - /** |
|
15 | - * Insert the permissions related to users table. |
|
16 | - */ |
|
17 | - DB::table('permissions')->insert( |
|
18 | - [ |
|
19 | - /** |
|
20 | - * Users model permissions. |
|
21 | - */ |
|
22 | - [ |
|
23 | - 'name' => 'save', |
|
24 | - 'model' => 'users', |
|
25 | - 'created_at' => \DB::raw('NOW()'), |
|
26 | - 'updated_at' => \DB::raw('NOW()') |
|
27 | - ], |
|
28 | - [ |
|
29 | - 'name' => 'delete', |
|
30 | - 'model' => 'users', |
|
31 | - 'created_at' => \DB::raw('NOW()'), |
|
32 | - 'updated_at' => \DB::raw('NOW()') |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'name' => 'find', |
|
36 | - 'model' => 'users', |
|
37 | - 'created_at' => \DB::raw('NOW()'), |
|
38 | - 'updated_at' => \DB::raw('NOW()') |
|
39 | - ], |
|
40 | - [ |
|
41 | - 'name' => 'list', |
|
42 | - 'model' => 'users', |
|
43 | - 'created_at' => \DB::raw('NOW()'), |
|
44 | - 'updated_at' => \DB::raw('NOW()') |
|
45 | - ], |
|
46 | - [ |
|
47 | - 'name' => 'search', |
|
48 | - 'model' => 'users', |
|
49 | - 'created_at' => \DB::raw('NOW()'), |
|
50 | - 'updated_at' => \DB::raw('NOW()') |
|
51 | - ], |
|
52 | - [ |
|
53 | - 'name' => 'findby', |
|
54 | - 'model' => 'users', |
|
55 | - 'created_at' => \DB::raw('NOW()'), |
|
56 | - 'updated_at' => \DB::raw('NOW()') |
|
57 | - ], |
|
58 | - [ |
|
59 | - 'name' => 'first', |
|
60 | - 'model' => 'users', |
|
61 | - 'created_at' => \DB::raw('NOW()'), |
|
62 | - 'updated_at' => \DB::raw('NOW()') |
|
63 | - ], |
|
64 | - [ |
|
65 | - 'name' => 'paginate', |
|
66 | - 'model' => 'users', |
|
67 | - 'created_at' => \DB::raw('NOW()'), |
|
68 | - 'updated_at' => \DB::raw('NOW()') |
|
69 | - ], |
|
70 | - [ |
|
71 | - 'name' => 'paginateby', |
|
72 | - 'model' => 'users', |
|
73 | - 'created_at' => \DB::raw('NOW()'), |
|
74 | - 'updated_at' => \DB::raw('NOW()') |
|
75 | - ], |
|
76 | - [ |
|
77 | - 'name' => 'assigngroups', |
|
78 | - 'model' => 'users', |
|
79 | - 'created_at' => \DB::raw('NOW()'), |
|
80 | - 'updated_at' => \DB::raw('NOW()') |
|
81 | - ], |
|
82 | - [ |
|
83 | - 'name' => 'block', |
|
84 | - 'model' => 'users', |
|
85 | - 'created_at' => \DB::raw('NOW()'), |
|
86 | - 'updated_at' => \DB::raw('NOW()') |
|
87 | - ], |
|
88 | - [ |
|
89 | - 'name' => 'unblock', |
|
90 | - 'model' => 'users', |
|
91 | - 'created_at' => \DB::raw('NOW()'), |
|
92 | - 'updated_at' => \DB::raw('NOW()') |
|
93 | - ], |
|
94 | - [ |
|
95 | - 'name' => 'group', |
|
96 | - 'model' => 'users', |
|
97 | - 'created_at' => \DB::raw('NOW()'), |
|
98 | - 'updated_at' => \DB::raw('NOW()') |
|
99 | - ], |
|
100 | - [ |
|
101 | - 'name' => 'deleted', |
|
102 | - 'model' => 'users', |
|
103 | - 'created_at' => \DB::raw('NOW()'), |
|
104 | - 'updated_at' => \DB::raw('NOW()') |
|
105 | - ], |
|
106 | - [ |
|
107 | - 'name' => 'restore', |
|
108 | - 'model' => 'users', |
|
109 | - 'created_at' => \DB::raw('NOW()'), |
|
110 | - 'updated_at' => \DB::raw('NOW()') |
|
111 | - ] |
|
112 | - ] |
|
113 | - ); |
|
7 | + /** |
|
8 | + * Run the database seeds. |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function run() |
|
13 | + { |
|
14 | + /** |
|
15 | + * Insert the permissions related to users table. |
|
16 | + */ |
|
17 | + DB::table('permissions')->insert( |
|
18 | + [ |
|
19 | + /** |
|
20 | + * Users model permissions. |
|
21 | + */ |
|
22 | + [ |
|
23 | + 'name' => 'save', |
|
24 | + 'model' => 'users', |
|
25 | + 'created_at' => \DB::raw('NOW()'), |
|
26 | + 'updated_at' => \DB::raw('NOW()') |
|
27 | + ], |
|
28 | + [ |
|
29 | + 'name' => 'delete', |
|
30 | + 'model' => 'users', |
|
31 | + 'created_at' => \DB::raw('NOW()'), |
|
32 | + 'updated_at' => \DB::raw('NOW()') |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'name' => 'find', |
|
36 | + 'model' => 'users', |
|
37 | + 'created_at' => \DB::raw('NOW()'), |
|
38 | + 'updated_at' => \DB::raw('NOW()') |
|
39 | + ], |
|
40 | + [ |
|
41 | + 'name' => 'list', |
|
42 | + 'model' => 'users', |
|
43 | + 'created_at' => \DB::raw('NOW()'), |
|
44 | + 'updated_at' => \DB::raw('NOW()') |
|
45 | + ], |
|
46 | + [ |
|
47 | + 'name' => 'search', |
|
48 | + 'model' => 'users', |
|
49 | + 'created_at' => \DB::raw('NOW()'), |
|
50 | + 'updated_at' => \DB::raw('NOW()') |
|
51 | + ], |
|
52 | + [ |
|
53 | + 'name' => 'findby', |
|
54 | + 'model' => 'users', |
|
55 | + 'created_at' => \DB::raw('NOW()'), |
|
56 | + 'updated_at' => \DB::raw('NOW()') |
|
57 | + ], |
|
58 | + [ |
|
59 | + 'name' => 'first', |
|
60 | + 'model' => 'users', |
|
61 | + 'created_at' => \DB::raw('NOW()'), |
|
62 | + 'updated_at' => \DB::raw('NOW()') |
|
63 | + ], |
|
64 | + [ |
|
65 | + 'name' => 'paginate', |
|
66 | + 'model' => 'users', |
|
67 | + 'created_at' => \DB::raw('NOW()'), |
|
68 | + 'updated_at' => \DB::raw('NOW()') |
|
69 | + ], |
|
70 | + [ |
|
71 | + 'name' => 'paginateby', |
|
72 | + 'model' => 'users', |
|
73 | + 'created_at' => \DB::raw('NOW()'), |
|
74 | + 'updated_at' => \DB::raw('NOW()') |
|
75 | + ], |
|
76 | + [ |
|
77 | + 'name' => 'assigngroups', |
|
78 | + 'model' => 'users', |
|
79 | + 'created_at' => \DB::raw('NOW()'), |
|
80 | + 'updated_at' => \DB::raw('NOW()') |
|
81 | + ], |
|
82 | + [ |
|
83 | + 'name' => 'block', |
|
84 | + 'model' => 'users', |
|
85 | + 'created_at' => \DB::raw('NOW()'), |
|
86 | + 'updated_at' => \DB::raw('NOW()') |
|
87 | + ], |
|
88 | + [ |
|
89 | + 'name' => 'unblock', |
|
90 | + 'model' => 'users', |
|
91 | + 'created_at' => \DB::raw('NOW()'), |
|
92 | + 'updated_at' => \DB::raw('NOW()') |
|
93 | + ], |
|
94 | + [ |
|
95 | + 'name' => 'group', |
|
96 | + 'model' => 'users', |
|
97 | + 'created_at' => \DB::raw('NOW()'), |
|
98 | + 'updated_at' => \DB::raw('NOW()') |
|
99 | + ], |
|
100 | + [ |
|
101 | + 'name' => 'deleted', |
|
102 | + 'model' => 'users', |
|
103 | + 'created_at' => \DB::raw('NOW()'), |
|
104 | + 'updated_at' => \DB::raw('NOW()') |
|
105 | + ], |
|
106 | + [ |
|
107 | + 'name' => 'restore', |
|
108 | + 'model' => 'users', |
|
109 | + 'created_at' => \DB::raw('NOW()'), |
|
110 | + 'updated_at' => \DB::raw('NOW()') |
|
111 | + ] |
|
112 | + ] |
|
113 | + ); |
|
114 | 114 | |
115 | 115 | /** |
116 | 116 | * Create Default users. |
117 | 117 | */ |
118 | 118 | DB::table('users')->insertGetId( |
119 | - [ |
|
119 | + [ |
|
120 | 120 | 'name' => 'Admin', |
121 | 121 | 'email' => '[email protected]', |
122 | 122 | 'password' => bcrypt('123456'), |
123 | 123 | 'created_at' => \DB::raw('NOW()'), |
124 | 124 | 'updated_at' => \DB::raw('NOW()') |
125 | 125 | ] |
126 | - ); |
|
127 | - } |
|
126 | + ); |
|
127 | + } |
|
128 | 128 | } |
@@ -4,14 +4,14 @@ discard block |
||
4 | 4 | |
5 | 5 | class AssignRelationsSeeder extends Seeder |
6 | 6 | { |
7 | - /** |
|
8 | - * Run the database seeds. |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function run() |
|
13 | - { |
|
14 | - $adminGroupId = DB::table('groups')->whereIn('name', 'admin')->select('id')->first()->id; |
|
7 | + /** |
|
8 | + * Run the database seeds. |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function run() |
|
13 | + { |
|
14 | + $adminGroupId = DB::table('groups')->whereIn('name', 'admin')->select('id')->first()->id; |
|
15 | 15 | $adminUserId = DB::table('users')->whereIn('email', '[email protected]')->select('id')->first()->id; |
16 | 16 | |
17 | 17 | /** |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | 'created_at' => \DB::raw('NOW()'), |
25 | 25 | 'updated_at' => \DB::raw('NOW()') |
26 | 26 | ] |
27 | - ); |
|
27 | + ); |
|
28 | 28 | |
29 | - /** |
|
29 | + /** |
|
30 | 30 | * Assign the permissions to the admin group. |
31 | 31 | */ |
32 | - DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups'])->each(function ($permission) use ($adminGroupId) { |
|
33 | - DB::table('groups_permissions')->insert( |
|
32 | + DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups'])->each(function ($permission) use ($adminGroupId) { |
|
33 | + DB::table('groups_permissions')->insert( |
|
34 | 34 | [ |
35 | 35 | 'permission_id' => $permission->id, |
36 | 36 | 'group_id' => $adminGroupId, |
@@ -38,6 +38,6 @@ discard block |
||
38 | 38 | 'updated_at' => \DB::raw('NOW()') |
39 | 39 | ] |
40 | 40 | ); |
41 | - }); |
|
42 | - } |
|
41 | + }); |
|
42 | + } |
|
43 | 43 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | public function run() |
13 | 13 | { |
14 | 14 | $adminGroupId = DB::table('groups')->whereIn('name', 'admin')->select('id')->first()->id; |
15 | - $adminUserId = DB::table('users')->whereIn('email', '[email protected]')->select('id')->first()->id; |
|
15 | + $adminUserId = DB::table('users')->whereIn('email', '[email protected]')->select('id')->first()->id; |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Assign users to groups. |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * Assign the permissions to the admin group. |
31 | 31 | */ |
32 | - DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups'])->each(function ($permission) use ($adminGroupId) { |
|
32 | + DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups'])->each(function($permission) use ($adminGroupId) { |
|
33 | 33 | DB::table('groups_permissions')->insert( |
34 | 34 | [ |
35 | 35 | 'permission_id' => $permission->id, |
@@ -4,64 +4,64 @@ |
||
4 | 4 | |
5 | 5 | class PermissionsTableSeeder extends Seeder |
6 | 6 | { |
7 | - /** |
|
8 | - * Run the database seeds. |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function run() |
|
13 | - { |
|
14 | - /** |
|
15 | - * Insert the permissions related to permissions table. |
|
16 | - */ |
|
17 | - DB::table('permissions')->insert( |
|
18 | - [ |
|
19 | - /** |
|
20 | - * Permissions model permissions. |
|
21 | - */ |
|
22 | - [ |
|
23 | - 'name' => 'find', |
|
24 | - 'model' => 'permissions', |
|
25 | - 'created_at' => \DB::raw('NOW()'), |
|
26 | - 'updated_at' => \DB::raw('NOW()') |
|
27 | - ], |
|
28 | - [ |
|
29 | - 'name' => 'search', |
|
30 | - 'model' => 'permissions', |
|
31 | - 'created_at' => \DB::raw('NOW()'), |
|
32 | - 'updated_at' => \DB::raw('NOW()') |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'name' => 'list', |
|
36 | - 'model' => 'permissions', |
|
37 | - 'created_at' => \DB::raw('NOW()'), |
|
38 | - 'updated_at' => \DB::raw('NOW()') |
|
39 | - ], |
|
40 | - [ |
|
41 | - 'name' => 'findby', |
|
42 | - 'model' => 'permissions', |
|
43 | - 'created_at' => \DB::raw('NOW()'), |
|
44 | - 'updated_at' => \DB::raw('NOW()') |
|
45 | - ], |
|
46 | - [ |
|
47 | - 'name' => 'first', |
|
48 | - 'model' => 'permissions', |
|
49 | - 'created_at' => \DB::raw('NOW()'), |
|
50 | - 'updated_at' => \DB::raw('NOW()') |
|
51 | - ], |
|
52 | - [ |
|
53 | - 'name' => 'paginate', |
|
54 | - 'model' => 'permissions', |
|
55 | - 'created_at' => \DB::raw('NOW()'), |
|
56 | - 'updated_at' => \DB::raw('NOW()') |
|
57 | - ], |
|
58 | - [ |
|
59 | - 'name' => 'paginateby', |
|
60 | - 'model' => 'permissions', |
|
61 | - 'created_at' => \DB::raw('NOW()'), |
|
62 | - 'updated_at' => \DB::raw('NOW()') |
|
63 | - ] |
|
64 | - ] |
|
65 | - ); |
|
66 | - } |
|
7 | + /** |
|
8 | + * Run the database seeds. |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function run() |
|
13 | + { |
|
14 | + /** |
|
15 | + * Insert the permissions related to permissions table. |
|
16 | + */ |
|
17 | + DB::table('permissions')->insert( |
|
18 | + [ |
|
19 | + /** |
|
20 | + * Permissions model permissions. |
|
21 | + */ |
|
22 | + [ |
|
23 | + 'name' => 'find', |
|
24 | + 'model' => 'permissions', |
|
25 | + 'created_at' => \DB::raw('NOW()'), |
|
26 | + 'updated_at' => \DB::raw('NOW()') |
|
27 | + ], |
|
28 | + [ |
|
29 | + 'name' => 'search', |
|
30 | + 'model' => 'permissions', |
|
31 | + 'created_at' => \DB::raw('NOW()'), |
|
32 | + 'updated_at' => \DB::raw('NOW()') |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'name' => 'list', |
|
36 | + 'model' => 'permissions', |
|
37 | + 'created_at' => \DB::raw('NOW()'), |
|
38 | + 'updated_at' => \DB::raw('NOW()') |
|
39 | + ], |
|
40 | + [ |
|
41 | + 'name' => 'findby', |
|
42 | + 'model' => 'permissions', |
|
43 | + 'created_at' => \DB::raw('NOW()'), |
|
44 | + 'updated_at' => \DB::raw('NOW()') |
|
45 | + ], |
|
46 | + [ |
|
47 | + 'name' => 'first', |
|
48 | + 'model' => 'permissions', |
|
49 | + 'created_at' => \DB::raw('NOW()'), |
|
50 | + 'updated_at' => \DB::raw('NOW()') |
|
51 | + ], |
|
52 | + [ |
|
53 | + 'name' => 'paginate', |
|
54 | + 'model' => 'permissions', |
|
55 | + 'created_at' => \DB::raw('NOW()'), |
|
56 | + 'updated_at' => \DB::raw('NOW()') |
|
57 | + ], |
|
58 | + [ |
|
59 | + 'name' => 'paginateby', |
|
60 | + 'model' => 'permissions', |
|
61 | + 'created_at' => \DB::raw('NOW()'), |
|
62 | + 'updated_at' => \DB::raw('NOW()') |
|
63 | + ] |
|
64 | + ] |
|
65 | + ); |
|
66 | + } |
|
67 | 67 | } |
@@ -4,101 +4,101 @@ discard block |
||
4 | 4 | |
5 | 5 | class GroupsTableSeeder extends Seeder |
6 | 6 | { |
7 | - /** |
|
8 | - * Run the database seeds. |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function run() |
|
13 | - { |
|
14 | - /** |
|
15 | - * Insert the permissions related to groups table. |
|
16 | - */ |
|
17 | - DB::table('permissions')->insert( |
|
18 | - [ |
|
19 | - /** |
|
20 | - * Groups model permissions. |
|
21 | - */ |
|
22 | - [ |
|
23 | - 'name' => 'save', |
|
24 | - 'model' => 'groups', |
|
25 | - 'created_at' => \DB::raw('NOW()'), |
|
26 | - 'updated_at' => \DB::raw('NOW()') |
|
27 | - ], |
|
28 | - [ |
|
29 | - 'name' => 'delete', |
|
30 | - 'model' => 'groups', |
|
31 | - 'created_at' => \DB::raw('NOW()'), |
|
32 | - 'updated_at' => \DB::raw('NOW()') |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'name' => 'find', |
|
36 | - 'model' => 'groups', |
|
37 | - 'created_at' => \DB::raw('NOW()'), |
|
38 | - 'updated_at' => \DB::raw('NOW()') |
|
39 | - ], |
|
40 | - [ |
|
41 | - 'name' => 'search', |
|
42 | - 'model' => 'groups', |
|
43 | - 'created_at' => \DB::raw('NOW()'), |
|
44 | - 'updated_at' => \DB::raw('NOW()') |
|
45 | - ], |
|
46 | - [ |
|
47 | - 'name' => 'list', |
|
48 | - 'model' => 'groups', |
|
49 | - 'created_at' => \DB::raw('NOW()'), |
|
50 | - 'updated_at' => \DB::raw('NOW()') |
|
51 | - ], |
|
52 | - [ |
|
53 | - 'name' => 'findby', |
|
54 | - 'model' => 'groups', |
|
55 | - 'created_at' => \DB::raw('NOW()'), |
|
56 | - 'updated_at' => \DB::raw('NOW()') |
|
57 | - ], |
|
58 | - [ |
|
59 | - 'name' => 'first', |
|
60 | - 'model' => 'groups', |
|
61 | - 'created_at' => \DB::raw('NOW()'), |
|
62 | - 'updated_at' => \DB::raw('NOW()') |
|
63 | - ], |
|
64 | - [ |
|
65 | - 'name' => 'paginate', |
|
66 | - 'model' => 'groups', |
|
67 | - 'created_at' => \DB::raw('NOW()'), |
|
68 | - 'updated_at' => \DB::raw('NOW()') |
|
69 | - ], |
|
70 | - [ |
|
71 | - 'name' => 'paginateby', |
|
72 | - 'model' => 'groups', |
|
73 | - 'created_at' => \DB::raw('NOW()'), |
|
74 | - 'updated_at' => \DB::raw('NOW()') |
|
75 | - ], |
|
76 | - [ |
|
77 | - 'name' => 'assignpermissions', |
|
78 | - 'model' => 'groups', |
|
79 | - 'created_at' => \DB::raw('NOW()'), |
|
80 | - 'updated_at' => \DB::raw('NOW()') |
|
81 | - ], |
|
82 | - [ |
|
83 | - 'name' => 'users', |
|
84 | - 'model' => 'groups', |
|
85 | - 'created_at' => \DB::raw('NOW()'), |
|
86 | - 'updated_at' => \DB::raw('NOW()') |
|
87 | - ], |
|
88 | - [ |
|
89 | - 'name' => 'deleted', |
|
90 | - 'model' => 'groups', |
|
91 | - 'created_at' => \DB::raw('NOW()'), |
|
92 | - 'updated_at' => \DB::raw('NOW()') |
|
93 | - ], |
|
94 | - [ |
|
95 | - 'name' => 'restore', |
|
96 | - 'model' => 'groups', |
|
97 | - 'created_at' => \DB::raw('NOW()'), |
|
98 | - 'updated_at' => \DB::raw('NOW()') |
|
99 | - ] |
|
100 | - ] |
|
101 | - ); |
|
7 | + /** |
|
8 | + * Run the database seeds. |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function run() |
|
13 | + { |
|
14 | + /** |
|
15 | + * Insert the permissions related to groups table. |
|
16 | + */ |
|
17 | + DB::table('permissions')->insert( |
|
18 | + [ |
|
19 | + /** |
|
20 | + * Groups model permissions. |
|
21 | + */ |
|
22 | + [ |
|
23 | + 'name' => 'save', |
|
24 | + 'model' => 'groups', |
|
25 | + 'created_at' => \DB::raw('NOW()'), |
|
26 | + 'updated_at' => \DB::raw('NOW()') |
|
27 | + ], |
|
28 | + [ |
|
29 | + 'name' => 'delete', |
|
30 | + 'model' => 'groups', |
|
31 | + 'created_at' => \DB::raw('NOW()'), |
|
32 | + 'updated_at' => \DB::raw('NOW()') |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'name' => 'find', |
|
36 | + 'model' => 'groups', |
|
37 | + 'created_at' => \DB::raw('NOW()'), |
|
38 | + 'updated_at' => \DB::raw('NOW()') |
|
39 | + ], |
|
40 | + [ |
|
41 | + 'name' => 'search', |
|
42 | + 'model' => 'groups', |
|
43 | + 'created_at' => \DB::raw('NOW()'), |
|
44 | + 'updated_at' => \DB::raw('NOW()') |
|
45 | + ], |
|
46 | + [ |
|
47 | + 'name' => 'list', |
|
48 | + 'model' => 'groups', |
|
49 | + 'created_at' => \DB::raw('NOW()'), |
|
50 | + 'updated_at' => \DB::raw('NOW()') |
|
51 | + ], |
|
52 | + [ |
|
53 | + 'name' => 'findby', |
|
54 | + 'model' => 'groups', |
|
55 | + 'created_at' => \DB::raw('NOW()'), |
|
56 | + 'updated_at' => \DB::raw('NOW()') |
|
57 | + ], |
|
58 | + [ |
|
59 | + 'name' => 'first', |
|
60 | + 'model' => 'groups', |
|
61 | + 'created_at' => \DB::raw('NOW()'), |
|
62 | + 'updated_at' => \DB::raw('NOW()') |
|
63 | + ], |
|
64 | + [ |
|
65 | + 'name' => 'paginate', |
|
66 | + 'model' => 'groups', |
|
67 | + 'created_at' => \DB::raw('NOW()'), |
|
68 | + 'updated_at' => \DB::raw('NOW()') |
|
69 | + ], |
|
70 | + [ |
|
71 | + 'name' => 'paginateby', |
|
72 | + 'model' => 'groups', |
|
73 | + 'created_at' => \DB::raw('NOW()'), |
|
74 | + 'updated_at' => \DB::raw('NOW()') |
|
75 | + ], |
|
76 | + [ |
|
77 | + 'name' => 'assignpermissions', |
|
78 | + 'model' => 'groups', |
|
79 | + 'created_at' => \DB::raw('NOW()'), |
|
80 | + 'updated_at' => \DB::raw('NOW()') |
|
81 | + ], |
|
82 | + [ |
|
83 | + 'name' => 'users', |
|
84 | + 'model' => 'groups', |
|
85 | + 'created_at' => \DB::raw('NOW()'), |
|
86 | + 'updated_at' => \DB::raw('NOW()') |
|
87 | + ], |
|
88 | + [ |
|
89 | + 'name' => 'deleted', |
|
90 | + 'model' => 'groups', |
|
91 | + 'created_at' => \DB::raw('NOW()'), |
|
92 | + 'updated_at' => \DB::raw('NOW()') |
|
93 | + ], |
|
94 | + [ |
|
95 | + 'name' => 'restore', |
|
96 | + 'model' => 'groups', |
|
97 | + 'created_at' => \DB::raw('NOW()'), |
|
98 | + 'updated_at' => \DB::raw('NOW()') |
|
99 | + ] |
|
100 | + ] |
|
101 | + ); |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Create Default groups. |
@@ -110,5 +110,5 @@ discard block |
||
110 | 110 | 'updated_at' => \DB::raw('NOW()') |
111 | 111 | ] |
112 | 112 | ); |
113 | - } |
|
113 | + } |
|
114 | 114 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * Generate headers for the given route. |
92 | 92 | * |
93 | 93 | * @param array &$route |
94 | - * @param object $reflectionClass |
|
94 | + * @param \ReflectionClass $reflectionClass |
|
95 | 95 | * @param string $method |
96 | 96 | * @param array $skipLoginCheck |
97 | 97 | * @return void |
@@ -118,6 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @param array &$route |
120 | 120 | * @param object $reflectionMethod] |
121 | + * @param \ReflectionMethod $reflectionMethod |
|
121 | 122 | * @return void |
122 | 123 | */ |
123 | 124 | protected function processDocBlock(&$route, $reflectionMethod) |
@@ -140,7 +141,7 @@ discard block |
||
140 | 141 | * Generate post body for the given route. |
141 | 142 | * |
142 | 143 | * @param array &$route |
143 | - * @param object $reflectionMethod |
|
144 | + * @param \ReflectionMethod $reflectionMethod |
|
144 | 145 | * @param array $validationRules |
145 | 146 | * @return void |
146 | 147 | */ |
@@ -6,223 +6,223 @@ |
||
6 | 6 | |
7 | 7 | class GenerateDoc extends Command |
8 | 8 | { |
9 | - /** |
|
10 | - * The name and signature of the console command. |
|
11 | - * |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - protected $signature = 'doc:generate'; |
|
15 | - |
|
16 | - /** |
|
17 | - * The console command description. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $description = 'Generate api documentation'; |
|
22 | - |
|
23 | - /** |
|
24 | - * Create a new command instance. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function __construct() |
|
29 | - { |
|
30 | - parent::__construct(); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Execute the console command. |
|
35 | - * |
|
36 | - * @return mixed |
|
37 | - */ |
|
38 | - public function handle() |
|
39 | - { |
|
40 | - $docData = []; |
|
41 | - $routes = $this->getRoutes(); |
|
42 | - foreach ($routes as $route) |
|
43 | - { |
|
44 | - if ($route) |
|
45 | - { |
|
46 | - $actoinArray = explode('@', $route['action']); |
|
47 | - $controller = $actoinArray[0]; |
|
48 | - $method = $actoinArray[1]; |
|
49 | - $route['name'] = $method !== 'index' ? $method : 'list'; |
|
9 | + /** |
|
10 | + * The name and signature of the console command. |
|
11 | + * |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + protected $signature = 'doc:generate'; |
|
15 | + |
|
16 | + /** |
|
17 | + * The console command description. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $description = 'Generate api documentation'; |
|
22 | + |
|
23 | + /** |
|
24 | + * Create a new command instance. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + parent::__construct(); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Execute the console command. |
|
35 | + * |
|
36 | + * @return mixed |
|
37 | + */ |
|
38 | + public function handle() |
|
39 | + { |
|
40 | + $docData = []; |
|
41 | + $routes = $this->getRoutes(); |
|
42 | + foreach ($routes as $route) |
|
43 | + { |
|
44 | + if ($route) |
|
45 | + { |
|
46 | + $actoinArray = explode('@', $route['action']); |
|
47 | + $controller = $actoinArray[0]; |
|
48 | + $method = $actoinArray[1]; |
|
49 | + $route['name'] = $method !== 'index' ? $method : 'list'; |
|
50 | 50 | |
51 | - $reflectionClass = new \ReflectionClass($controller); |
|
52 | - $reflectionMethod = $reflectionClass->getMethod($method); |
|
53 | - $classProperties = $reflectionClass->getDefaultProperties(); |
|
54 | - $skipLoginCheck = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false; |
|
55 | - $validationRules = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false; |
|
56 | - |
|
57 | - $this->processDocBlock($route, $reflectionMethod); |
|
58 | - $this->getHeaders($route, $reflectionClass, $method, $skipLoginCheck); |
|
59 | - $this->getPostData($route, $reflectionMethod, $validationRules); |
|
60 | - |
|
61 | - preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module); |
|
62 | - preg_match('/api\/v1\/' . $module[1] . '\/([^#]+)\//iU', $route['uri'], $model); |
|
63 | - $docData['modules'][$module[1]][$model[1]][] = $route; |
|
64 | - } |
|
65 | - } |
|
66 | - $docData['errors'] = $this->getErrors(); |
|
67 | - \File::put(app_path('Modules/V1/Core/Resources/api.json'), json_encode($docData)); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Get list of all registered routes. |
|
72 | - * |
|
73 | - * @return collection |
|
74 | - */ |
|
75 | - protected function getRoutes() |
|
76 | - { |
|
77 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
78 | - if (strpos($route->uri(), 'api/v') !== false) |
|
79 | - { |
|
80 | - return [ |
|
81 | - 'method' => $route->methods()[0], |
|
82 | - 'uri' => $route->uri(), |
|
83 | - 'action' => $route->getActionName() |
|
84 | - ]; |
|
85 | - } |
|
86 | - return false; |
|
87 | - })->all(); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Generate headers for the given route. |
|
92 | - * |
|
93 | - * @param array &$route |
|
94 | - * @param object $reflectionClass |
|
95 | - * @param string $method |
|
96 | - * @param array $skipLoginCheck |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - protected function getHeaders(&$route, $reflectionClass, $method, $skipLoginCheck) |
|
100 | - { |
|
101 | - $route['headers'] = [ |
|
102 | - 'Accept' => 'application/json', |
|
103 | - 'Content-Type' => 'application/json', |
|
104 | - 'locale' => 'The language of the returned data: ar, en or all.', |
|
105 | - 'time-zone-diff' => 'Timezone difference between UTC and Local Time', |
|
106 | - ]; |
|
107 | - |
|
108 | - |
|
109 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) |
|
110 | - { |
|
111 | - $route['headers']['Authrization'] = 'bearer {token}'; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Generate description and params for the given route |
|
117 | - * based on the docblock. |
|
118 | - * |
|
119 | - * @param array &$route |
|
120 | - * @param object $reflectionMethod] |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - protected function processDocBlock(&$route, $reflectionMethod) |
|
124 | - { |
|
125 | - $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
126 | - $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
127 | - $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
128 | - $params = $docblock->getTagsByName('param'); |
|
129 | - foreach ($params as $param) |
|
130 | - { |
|
131 | - $name = $param->getVariableName(); |
|
132 | - if ($name !== 'request') |
|
133 | - { |
|
134 | - $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Generate post body for the given route. |
|
141 | - * |
|
142 | - * @param array &$route |
|
143 | - * @param object $reflectionMethod |
|
144 | - * @param array $validationRules |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - protected function getPostData(&$route, $reflectionMethod, $validationRules) |
|
148 | - { |
|
149 | - if ($route['method'] == 'POST') |
|
150 | - { |
|
151 | - $body = $this->getMethodBody($reflectionMethod); |
|
152 | - |
|
153 | - preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match); |
|
154 | - if (count($match)) |
|
155 | - { |
|
156 | - if ($match[1] == '$this->validationRules') |
|
157 | - { |
|
158 | - $route['body'] = $validationRules; |
|
159 | - } |
|
160 | - else |
|
161 | - { |
|
162 | - $route['body'] = eval('return ' . $match[1] . ';'); |
|
163 | - } |
|
164 | - |
|
165 | - foreach ($route['body'] as &$rule) |
|
166 | - { |
|
167 | - if(strpos($rule, 'unique')) |
|
168 | - { |
|
169 | - $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
170 | - } |
|
171 | - elseif(strpos($rule, 'exists')) |
|
172 | - { |
|
173 | - $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
177 | - else |
|
178 | - { |
|
179 | - $route['body'] = 'conditions'; |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Generate application errors. |
|
186 | - * |
|
187 | - * @return array |
|
188 | - */ |
|
189 | - protected function getErrors() |
|
190 | - { |
|
191 | - $errors = []; |
|
192 | - $reflectionClass = new \ReflectionClass('App\Modules\V1\Core\Utl\ErrorHandler'); |
|
193 | - foreach ($reflectionClass->getMethods() as $method) |
|
194 | - { |
|
195 | - $methodName = $method->getName(); |
|
196 | - $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
197 | - $body = $this->getMethodBody($reflectionMethod); |
|
198 | - |
|
199 | - preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
200 | - |
|
201 | - if (count($match)) |
|
202 | - { |
|
203 | - $errors[$match[1]][] = $methodName; |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - return $errors; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Get the fiven method body code. |
|
212 | - * |
|
213 | - * @param object $reflectionMethod |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - protected function getMethodBody($reflectionMethod) |
|
217 | - { |
|
218 | - $filename = $reflectionMethod->getFileName(); |
|
219 | - $start_line = $reflectionMethod->getStartLine() - 1; |
|
220 | - $end_line = $reflectionMethod->getEndLine(); |
|
221 | - $length = $end_line - $start_line; |
|
222 | - $source = file($filename); |
|
223 | - $body = implode("", array_slice($source, $start_line, $length)); |
|
224 | - $body = trim(preg_replace('/\s+/', '', $body)); |
|
225 | - |
|
226 | - return $body; |
|
227 | - } |
|
51 | + $reflectionClass = new \ReflectionClass($controller); |
|
52 | + $reflectionMethod = $reflectionClass->getMethod($method); |
|
53 | + $classProperties = $reflectionClass->getDefaultProperties(); |
|
54 | + $skipLoginCheck = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false; |
|
55 | + $validationRules = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false; |
|
56 | + |
|
57 | + $this->processDocBlock($route, $reflectionMethod); |
|
58 | + $this->getHeaders($route, $reflectionClass, $method, $skipLoginCheck); |
|
59 | + $this->getPostData($route, $reflectionMethod, $validationRules); |
|
60 | + |
|
61 | + preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module); |
|
62 | + preg_match('/api\/v1\/' . $module[1] . '\/([^#]+)\//iU', $route['uri'], $model); |
|
63 | + $docData['modules'][$module[1]][$model[1]][] = $route; |
|
64 | + } |
|
65 | + } |
|
66 | + $docData['errors'] = $this->getErrors(); |
|
67 | + \File::put(app_path('Modules/V1/Core/Resources/api.json'), json_encode($docData)); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Get list of all registered routes. |
|
72 | + * |
|
73 | + * @return collection |
|
74 | + */ |
|
75 | + protected function getRoutes() |
|
76 | + { |
|
77 | + return collect(\Route::getRoutes())->map(function ($route) { |
|
78 | + if (strpos($route->uri(), 'api/v') !== false) |
|
79 | + { |
|
80 | + return [ |
|
81 | + 'method' => $route->methods()[0], |
|
82 | + 'uri' => $route->uri(), |
|
83 | + 'action' => $route->getActionName() |
|
84 | + ]; |
|
85 | + } |
|
86 | + return false; |
|
87 | + })->all(); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Generate headers for the given route. |
|
92 | + * |
|
93 | + * @param array &$route |
|
94 | + * @param object $reflectionClass |
|
95 | + * @param string $method |
|
96 | + * @param array $skipLoginCheck |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + protected function getHeaders(&$route, $reflectionClass, $method, $skipLoginCheck) |
|
100 | + { |
|
101 | + $route['headers'] = [ |
|
102 | + 'Accept' => 'application/json', |
|
103 | + 'Content-Type' => 'application/json', |
|
104 | + 'locale' => 'The language of the returned data: ar, en or all.', |
|
105 | + 'time-zone-diff' => 'Timezone difference between UTC and Local Time', |
|
106 | + ]; |
|
107 | + |
|
108 | + |
|
109 | + if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) |
|
110 | + { |
|
111 | + $route['headers']['Authrization'] = 'bearer {token}'; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Generate description and params for the given route |
|
117 | + * based on the docblock. |
|
118 | + * |
|
119 | + * @param array &$route |
|
120 | + * @param object $reflectionMethod] |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + protected function processDocBlock(&$route, $reflectionMethod) |
|
124 | + { |
|
125 | + $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
126 | + $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
127 | + $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
128 | + $params = $docblock->getTagsByName('param'); |
|
129 | + foreach ($params as $param) |
|
130 | + { |
|
131 | + $name = $param->getVariableName(); |
|
132 | + if ($name !== 'request') |
|
133 | + { |
|
134 | + $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Generate post body for the given route. |
|
141 | + * |
|
142 | + * @param array &$route |
|
143 | + * @param object $reflectionMethod |
|
144 | + * @param array $validationRules |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + protected function getPostData(&$route, $reflectionMethod, $validationRules) |
|
148 | + { |
|
149 | + if ($route['method'] == 'POST') |
|
150 | + { |
|
151 | + $body = $this->getMethodBody($reflectionMethod); |
|
152 | + |
|
153 | + preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match); |
|
154 | + if (count($match)) |
|
155 | + { |
|
156 | + if ($match[1] == '$this->validationRules') |
|
157 | + { |
|
158 | + $route['body'] = $validationRules; |
|
159 | + } |
|
160 | + else |
|
161 | + { |
|
162 | + $route['body'] = eval('return ' . $match[1] . ';'); |
|
163 | + } |
|
164 | + |
|
165 | + foreach ($route['body'] as &$rule) |
|
166 | + { |
|
167 | + if(strpos($rule, 'unique')) |
|
168 | + { |
|
169 | + $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
170 | + } |
|
171 | + elseif(strpos($rule, 'exists')) |
|
172 | + { |
|
173 | + $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | + else |
|
178 | + { |
|
179 | + $route['body'] = 'conditions'; |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Generate application errors. |
|
186 | + * |
|
187 | + * @return array |
|
188 | + */ |
|
189 | + protected function getErrors() |
|
190 | + { |
|
191 | + $errors = []; |
|
192 | + $reflectionClass = new \ReflectionClass('App\Modules\V1\Core\Utl\ErrorHandler'); |
|
193 | + foreach ($reflectionClass->getMethods() as $method) |
|
194 | + { |
|
195 | + $methodName = $method->getName(); |
|
196 | + $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
197 | + $body = $this->getMethodBody($reflectionMethod); |
|
198 | + |
|
199 | + preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
200 | + |
|
201 | + if (count($match)) |
|
202 | + { |
|
203 | + $errors[$match[1]][] = $methodName; |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + return $errors; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Get the fiven method body code. |
|
212 | + * |
|
213 | + * @param object $reflectionMethod |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + protected function getMethodBody($reflectionMethod) |
|
217 | + { |
|
218 | + $filename = $reflectionMethod->getFileName(); |
|
219 | + $start_line = $reflectionMethod->getStartLine() - 1; |
|
220 | + $end_line = $reflectionMethod->getEndLine(); |
|
221 | + $length = $end_line - $start_line; |
|
222 | + $source = file($filename); |
|
223 | + $body = implode("", array_slice($source, $start_line, $length)); |
|
224 | + $body = trim(preg_replace('/\s+/', '', $body)); |
|
225 | + |
|
226 | + return $body; |
|
227 | + } |
|
228 | 228 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $this->getPostData($route, $reflectionMethod, $validationRules); |
60 | 60 | |
61 | 61 | preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module); |
62 | - preg_match('/api\/v1\/' . $module[1] . '\/([^#]+)\//iU', $route['uri'], $model); |
|
62 | + preg_match('/api\/v1\/'.$module[1].'\/([^#]+)\//iU', $route['uri'], $model); |
|
63 | 63 | $docData['modules'][$module[1]][$model[1]][] = $route; |
64 | 64 | } |
65 | 65 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function getRoutes() |
76 | 76 | { |
77 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
77 | + return collect(\Route::getRoutes())->map(function($route) { |
|
78 | 78 | if (strpos($route->uri(), 'api/v') !== false) |
79 | 79 | { |
80 | 80 | return [ |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | ]; |
107 | 107 | |
108 | 108 | |
109 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) |
|
109 | + if ( ! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) |
|
110 | 110 | { |
111 | 111 | $route['headers']['Authrization'] = 'bearer {token}'; |
112 | 112 | } |
@@ -159,16 +159,16 @@ discard block |
||
159 | 159 | } |
160 | 160 | else |
161 | 161 | { |
162 | - $route['body'] = eval('return ' . $match[1] . ';'); |
|
162 | + $route['body'] = eval('return '.$match[1].';'); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | foreach ($route['body'] as &$rule) |
166 | 166 | { |
167 | - if(strpos($rule, 'unique')) |
|
167 | + if (strpos($rule, 'unique')) |
|
168 | 168 | { |
169 | 169 | $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
170 | 170 | } |
171 | - elseif(strpos($rule, 'exists')) |
|
171 | + elseif (strpos($rule, 'exists')) |
|
172 | 172 | { |
173 | 173 | $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
174 | 174 | } |
@@ -156,8 +156,7 @@ discard block |
||
156 | 156 | if ($match[1] == '$this->validationRules') |
157 | 157 | { |
158 | 158 | $route['body'] = $validationRules; |
159 | - } |
|
160 | - else |
|
159 | + } else |
|
161 | 160 | { |
162 | 161 | $route['body'] = eval('return ' . $match[1] . ';'); |
163 | 162 | } |
@@ -167,14 +166,12 @@ discard block |
||
167 | 166 | if(strpos($rule, 'unique')) |
168 | 167 | { |
169 | 168 | $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
170 | - } |
|
171 | - elseif(strpos($rule, 'exists')) |
|
169 | + } elseif(strpos($rule, 'exists')) |
|
172 | 170 | { |
173 | 171 | $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
174 | 172 | } |
175 | 173 | } |
176 | - } |
|
177 | - else |
|
174 | + } else |
|
178 | 175 | { |
179 | 176 | $route['body'] = 'conditions'; |
180 | 177 | } |