Process flow (5/5 All 5 patterns) | FollowProcess flow Submenu
2017-11-25 release
2021-03-09 update
- http://mini-blog.localhost/user/user3URL'Follow' button
- SeeCheckpoint | Object-Orientation← point
- Follow http://mini-blog.localhost/followFollow button
- Seescreen SeeTest Data
- Login User ID: user1, Password: password
- index.php1require'../bootstrap.php'set autoloadit is omitted belowSeeAccount registration screen (User registration screen)
- index.php1require'../MiniBlogApplication.php'it is omitted below
- index.php1newMiniBlogApplication$app = new MiniBlogApplication(false)it is omitted below
- index.php1run(MiniBlogApplication.php)
- Application (core)2run
- $params = $this->router->resolve($this->request->getPathInfo())details↓
- Request (core)3getPathInfo'/follow'SeeCheckpoint | Request
- Request (core)4getBaseUrl
- Request (core)5getRequestUri
- Request (core)4getRequestUri
- Router (core)3resolve'account', 'follow'$params['controller'], $params['action']SeeCheckpoint | Router← point
- Application (core)3runAction'account', 'follow'
- Application (core)4findController!class_exists'AccountController'
- ClassLoader (core)5loadClass'AccountController'require'AccountController.php'/core /models
- Application (core)5getControllerDir
- MiniBlogApplication6getRootDir
- Application (core)5require_once'AccountController.php'/controllersSeeCheckpoint | Application
- class AccountController extends Controller
- ClassLoader (core)6loadClass'Controller'
- ClassLoader (core)7require'Controller.php'
- return new $controller_class($this)new use variabledetails↓
- Application (core)5new$controller_class = 'AccountController'MiniBlogApplication
- Controller (core)6__constructMiniBlogApplicationSeeCheckpoint | Controller
- Application (core)7getRequest
- Application (core)7getResponse
- Application (core)7getSession
- Application (core)7getDbManager
- $content = $controller->run($action, $params)details↓
- Controller (core)4run(AccountController)'account', 'follow''followAction'
- needsAuthentication($action) && isAuthenticated()denyNot Logindetails↓
- $auth_actions = array('index', 'signout', 'follow') (AccountController.php line 10)
- Controller (core)5needsAuthentication'follow'trueLogin Necessary
- Session (core)5isAuthenticated
- Session (core)6gettrue'_authenticated'Login Deny false
- Process start --- before Action start↘Process flow is almost the same except Controller and Actiononly Transition to Login, add Exception
- $content = $this->$action_method($params) variable functions$content = AccountController->followAction()
- AccountController5followActionAction start
- Request (core)6isPosttruePOSTfalse Not POST forward404()
- Request (core)6getPost'following_name'$following_name 'user3'
- if (!$following_name)No follow name forward404()
- Request (core)6getPost'_token'Contribution list http://mini-blog.localhost/user/user3 generateCsrfTokenSeeCheckpoint | Request
- Controller (core)6checkCsrfToken'account/follow'trueTokenfalse None Token redirect('/user/' . $following_name)SeeCheckpoint | Controller
- Session (core)7get'csrf_tokens/account/follow'SeeCheckpoint | Session
- Session (core)7set'csrf_tokens/account/follow'
- $follow_user = $this->db_manager->get('User')->fetchByUserName($following_name)$following_name 'user3'$follow_user 'user3' 1 record details↓
- DbManager (core)6get'User'get('User') 1stUserRepository
- DbManager (core)7getConnectionForRepository'User'DbManager->repository_connection_map['User']
- DbManager (core)8getConnection
- DbManager (core)8getConnectionreturn current(DbManager->connections)DbManager->connections['master'] = $con↙
- DbManager (core)7getConnectionForRepositoryreturn $con
- $repository = new $repository_class($con)new use variabledetails↓
- DbManager (core)7new$repository_class = 'UserRepository'$con
- ClassLoader (core)8loadClass'UserRepository'
- ClassLoader (core)9require'UserRepository.php'
- class UserRepository extends DbRepository
- ClassLoader (core)10loadClass'DbRepository'
- ClassLoader (core)11require'DbRepository.php'
- DbRepository (core)8__construct'$con'
- DbRepository (core)9setConnectionUserRepository->con = $con↗
- DbManager (core)6getDbManager->repositories['User']=>UserRepository
- DbManager (core)6getreturn DbManager->repositories['User']
- UserRepository6fetchByUserName$following_name 'user3'$follow_user 'user3' 1 recordSeeTest DataSeeSQL
- DbRepository (core)7fetch'user3'SeeCheckpoint | DbRepository
- DbRepository (core)8execute
- UserRepository6fetchByUserName
- if (!$follow_user)No follow forward404()
- Session (core)6get'user1' 1 record (Login user)$user
- $following_repository = $this->db_manager->get('Following')FollowingRepositorydetails↓
- DbManager (core)6get'Following'get('Following') 1stFollowingRepository
- DbManager (core)7getConnectionForRepository'Following'DbManager->repository_connection_map['Following']
- DbManager (core)8getConnection
- DbManager (core)8getConnectionreturn current(DbManager->connections)DbManager->connections['master'] = $con↙
- DbManager (core)7getConnectionForRepositoryreturn $con
- $repository = new $repository_class($con)new use variabledetails↓
- DbManager (core)7new$repository_class = 'FollowingRepository'$con
- ClassLoader (core)8loadClass'FollowingRepository'DbRepository loaded
- ClassLoader (core)9require'FollowingRepository.php'
- DbRepository (core)8__construct'$con'
- DbRepository (core)9setConnectionFollowingRepository->con = $con↗
- DbManager (core)6getDbManager->repositories['Following']=>FollowingRepository
- DbManager (core)6getreturn DbManager->repositories['Following']
- if ($user['id'] !== $follow_user['id'] && !$following_repository->isFollowing($user['id'], $follow_user['id'])details↓
- $user['id']: 1, $follow_user['id']: 3SeeTest Data
- FollowingRepository6isFollowingfalse denytrueSeeSQL
- DbRepository (core)7fetchSeeCheckpoint | DbRepository
- DbRepository (core)8execute
- isFollowing (true: Follow, false: No Follow) denytrue: No Follow
- FollowingRepository6isFollowing
- $following_repository->insert($user['id'], $follow_user['id'])details↓
- FollowingRepository6insert1, 3$user['id'], $follow_user['id']SeeTest DataSeeSQL
- DbRepository (core)7executeSeeCheckpoint | DbRepository
- FollowingRepository6insert
- Controller (core)6redirect'/account'
- Request (core)7isSslfalse
- Request (core)7getHost
- Request (core)7getBaseUrl
- Request (core)8getRequestUri
- $urlhttp://mini-blog.localhost/account
- Response (core)7setStatusCode
- Response (core)7setHttpHeader
- Controller (core)6redirect
- AccountController5followActionreturn AccountController->...Action end
- Controller (core)4runreturn $content$content: null
- Response (core)4setContentResponse->content = $content
- Application (core)3runAction
- Response (core)3sendecho Response->content
- Application (core)2run
- DbManager (core)2__destruct
note showing $this
e.g. $this->request → MiniBlogApplication->request
SQL
check SQL (phpMyAdmin, select SQL TAB) http://localhost/phpmyadmin/db_sql.php?db=mini_blog
fetchByUserName
SELECT * FROM user WHERE user_name = '
user3'
id | user_name | password | created_at |
---|---|---|---|
3 | user3 | ee5281d035bd1bd7786301be4274a68b006ae916 | 2017-11-01 00:00:00 |
isFollowing
SELECT COUNT(user_id) as count FROM following WHERE user_id =
1AND following_id =
3
count | 0 |
(reference) following table
user_id | following_id |
---|---|
1 | 2 |
insert
INSERT INTO following VALUES(1, 3)
user_id | following_id |
---|---|
1 | 3 |
Mini Blog Application
Follow
Creation procedure |
class | |
---|---|---|
Database | UserRepository FollowingRepository FollowingRepository |
fetchByUserName isFollowing insert |
Routing | MiniBlogApplication | '/follow' => array('controller' => 'account', 'action' => 'follow') |
Controller | AccountController | followAction |
View file |
function | class | method |
---|---|---|
Check | Request | isPost POST check |
- | if (!$following_name) No follow name | |
Controller | checkCsrfToken('account/follow', $token) Token check | |
- | if (!$follow_user) No follow | |
- | if ($user['id'] !== $follow_user['id'] 1, 3 | |
FollowingRepository | isFollowing($user['id'], $follow_user['id']) 1, 3 (deny false) true |
|
Data set | ||
Data get | Request |
Contribution list http://mini-blog.localhost/user/user3 getPost('following_name') 'user3' (Contribution list $user['user_name']) getPost('_token') '4b710f10e11206dd0e5ba2b23fea9c993b20a6c3' |
DbManager | get('User') UserRepository | |
UserRepository | fetchByUserName($following_name) 'user3' 1record | |
Session | get('user') Login user ('user1' 1record) | |
DbManager | get('Following') FollowingRepository | |
Data output | FollowingRepository | insert($user['id'], $follow_user['id']) 1, 3 |
Screen | Controller | forward404() 404 error screen (POST error, No follow name error, No follow error) |
Controller |
redirect('/account') Account information (Logined error) redirect('/user/user3') Contribution list (Token error) redirect('/account') Account information |
Login User ID: user1, Password: password.
You input http://mini-blog.localhost/user/user3 in URL, 'Follow' button screen is displayed.