Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
4fd88051
Commit
4fd88051
authored
Jul 24, 2020
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add dependency injection to Controllers
parent
be4f6d21
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
43 additions
and
26 deletions
+43
-26
page.php
qa-include/app/page.php
+1
-1
Points.php
qa-src/Controllers/Admin/Points.php
+5
-4
Stats.php
qa-src/Controllers/Admin/Stats.php
+5
-4
BaseController.php
qa-src/Controllers/BaseController.php
+5
-4
Ip.php
qa-src/Controllers/User/Ip.php
+5
-3
UserMessages.php
qa-src/Controllers/User/UserMessages.php
+5
-3
UserPosts.php
qa-src/Controllers/User/UserPosts.php
+6
-2
UserProfile.php
qa-src/Controllers/User/UserProfile.php
+6
-2
UsersList.php
qa-src/Controllers/User/UsersList.php
+5
-3
No files found.
qa-include/app/page.php
View file @
4fd88051
...
...
@@ -187,7 +187,7 @@ function qa_get_request_content()
if
(
$route
!==
null
)
{
qa_set_template
(
$route
->
getOption
(
'template'
));
$controllerClass
=
$route
->
getController
();
$ctrl
=
new
$controllerClass
();
$ctrl
=
new
$controllerClass
(
qa_service
(
'database'
)
);
$qa_content
=
$ctrl
->
executeAction
(
$route
->
getAction
(),
$route
->
getParameters
());
}
...
...
qa-src/Controllers/Admin/Points.php
View file @
4fd88051
...
...
@@ -18,15 +18,16 @@
namespace
Q2A\Controllers\Admin
;
use
Q2A\Auth\NoPermissionException
;
use
Q2A\Database\DbConnection
;
use
Q2A\Controllers\BaseController
;
use
Q2A\Middleware\Auth\MinimumUserLevel
;
/**
* Controller for admin page for settings about user points
*/
class
Points
extends
\Q2A\Controllers\
BaseController
class
Points
extends
BaseController
{
public
function
__construct
()
public
function
__construct
(
DbConnection
$db
)
{
require_once
QA_INCLUDE_DIR
.
'db/recalc.php'
;
require_once
QA_INCLUDE_DIR
.
'db/points.php'
;
...
...
@@ -34,7 +35,7 @@ class Points extends \Q2A\Controllers\BaseController
require_once
QA_INCLUDE_DIR
.
'app/admin.php'
;
require_once
QA_INCLUDE_DIR
.
'util/sort.php'
;
parent
::
__construct
();
parent
::
__construct
(
$db
);
$this
->
addMiddleware
(
new
MinimumUserLevel
(
QA_USER_LEVEL_ADMIN
));
}
...
...
qa-src/Controllers/Admin/Stats.php
View file @
4fd88051
...
...
@@ -18,22 +18,23 @@
namespace
Q2A\Controllers\Admin
;
use
Q2A\Auth\NoPermissionException
;
use
Q2A\Controllers\BaseController
;
use
Q2A\Database\DbConnection
;
use
Q2A\Middleware\Auth\MinimumUserLevel
;
/**
* Controller for admin page showing usage statistics and clean-up buttons
*/
class
Stats
extends
\Q2A\Controllers\
BaseController
class
Stats
extends
BaseController
{
public
function
__construct
()
public
function
__construct
(
DbConnection
$db
)
{
require_once
QA_INCLUDE_DIR
.
'db/recalc.php'
;
require_once
QA_INCLUDE_DIR
.
'app/admin.php'
;
require_once
QA_INCLUDE_DIR
.
'db/admin.php'
;
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
parent
::
__construct
();
parent
::
__construct
(
$db
);
$this
->
addMiddleware
(
new
MinimumUserLevel
(
QA_USER_LEVEL_ADMIN
));
}
...
...
qa-src/Controllers/BaseController.php
View file @
4fd88051
...
...
@@ -18,17 +18,18 @@
namespace
Q2A\Controllers
;
use
Q2A\Database\DbConnection
;
use
Q2A\Middleware\BaseMiddleware
;
abstract
class
BaseController
{
/** @var BaseMiddleware[string] */
private
$middleware
;
protected
$middleware
=
[];
protected
$db
;
public
function
__construct
()
public
function
__construct
(
DbConnection
$db
)
{
// TODO: constructor taking Database class parameter
$this
->
middleware
=
array
();
$this
->
db
=
$db
;
}
/**
...
...
qa-src/Controllers/User/Ip.php
View file @
4fd88051
...
...
@@ -19,18 +19,20 @@
namespace
Q2A\Controllers\User
;
use
Q2A\Auth\NoPermissionException
;
use
Q2A\Controllers\BaseController
;
use
Q2A\Database\DbConnection
;
/**
* Controller for page showing recent activity for an IP address
*/
class
Ip
extends
\Q2A\Controllers\
BaseController
class
Ip
extends
BaseController
{
public
function
__construct
()
public
function
__construct
(
DbConnection
$db
)
{
require_once
QA_INCLUDE_DIR
.
'db/selects.php'
;
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
parent
::
__construct
();
parent
::
__construct
(
$db
);
}
public
function
address
(
$ip
)
...
...
qa-src/Controllers/User/UserMessages.php
View file @
4fd88051
...
...
@@ -18,17 +18,19 @@
namespace
Q2A\Controllers\User
;
use
Q2A\Controllers\BaseController
;
use
Q2A\Database\DbConnection
;
use
Q2A\Http\Exceptions\PageNotFoundException
;
use
Q2A\Middleware\Auth\InternalUsersOnly
;
class
UserMessages
extends
\Q2A\Controllers\
BaseController
class
UserMessages
extends
BaseController
{
public
function
__construct
()
public
function
__construct
(
DbConnection
$db
)
{
require_once
QA_INCLUDE_DIR
.
'db/selects.php'
;
require_once
QA_INCLUDE_DIR
.
'app/messages.php'
;
parent
::
__construct
();
parent
::
__construct
(
$db
);
$this
->
addMiddleware
(
new
InternalUsersOnly
());
}
...
...
qa-src/Controllers/User/UserPosts.php
View file @
4fd88051
...
...
@@ -18,19 +18,23 @@
namespace
Q2A\Controllers\User
;
use
Q2A\Controllers\BaseController
;
use
Q2A\Database\DbConnection
;
use
Q2A\Http\Exceptions\PageNotFoundException
;
class
UserPosts
extends
\Q2A\Controllers\
BaseController
class
UserPosts
extends
BaseController
{
protected
$userid
;
protected
$userhtml
;
public
function
__construct
()
public
function
__construct
(
DbConnection
$db
)
{
require_once
QA_INCLUDE_DIR
.
'db/users.php'
;
require_once
QA_INCLUDE_DIR
.
'db/selects.php'
;
require_once
QA_INCLUDE_DIR
.
'app/users.php'
;
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
parent
::
__construct
(
$db
);
}
/**
...
...
qa-src/Controllers/User/UserProfile.php
View file @
4fd88051
...
...
@@ -18,19 +18,23 @@
namespace
Q2A\Controllers\User
;
use
Q2A\Controllers\BaseController
;
use
Q2A\Database\DbConnection
;
use
Q2A\Http\Exceptions\PageNotFoundException
;
class
UserProfile
extends
\Q2A\Controllers\
BaseController
class
UserProfile
extends
BaseController
{
private
$userid
;
private
$userhtml
;
public
function
__construct
()
public
function
__construct
(
DbConnection
$db
)
{
require_once
QA_INCLUDE_DIR
.
'db/users.php'
;
require_once
QA_INCLUDE_DIR
.
'db/selects.php'
;
require_once
QA_INCLUDE_DIR
.
'app/users.php'
;
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
parent
::
__construct
(
$db
);
}
public
function
index
()
...
...
qa-src/Controllers/User/UsersList.php
View file @
4fd88051
...
...
@@ -19,19 +19,21 @@
namespace
Q2A\Controllers\User
;
use
Q2A\Auth\NoPermissionException
;
use
Q2A\Controllers\BaseController
;
use
Q2A\Database\DbConnection
;
use
Q2A\Middleware\Auth\InternalUsersOnly
;
use
Q2A\Middleware\Auth\MinimumUserLevel
;
class
UsersList
extends
\Q2A\Controllers\
BaseController
class
UsersList
extends
BaseController
{
public
function
__construct
()
public
function
__construct
(
DbConnection
$db
)
{
require_once
QA_INCLUDE_DIR
.
'db/users.php'
;
require_once
QA_INCLUDE_DIR
.
'db/selects.php'
;
require_once
QA_INCLUDE_DIR
.
'app/users.php'
;
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
parent
::
__construct
();
parent
::
__construct
(
$db
);
$this
->
addMiddleware
(
new
InternalUsersOnly
(),
array
(
'newest'
,
'special'
,
'blocked'
));
$this
->
addMiddleware
(
new
MinimumUserLevel
(
QA_USER_LEVEL_MODERATOR
),
array
(
'blocked'
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment