Skip to content

Commit 2c92beb

Browse files
authored
Merge pull request #64 from uzulla/psr4ize
PSR-4対応リファクタリング
2 parents 4722c91 + 645ea78 commit 2c92beb

File tree

190 files changed

+1787
-1448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+1787
-1448
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/app/temp/blog_template/*
22
/app/temp/debug_html/*
33
/app/temp/log/*
4+
/app/vendor/
45
/public/uploads/[0-9a-zA-Z]
56
/public/config.php
67
/dump_data.sql

app/config/admin.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
$config = array();
44

5-
$config['APP_PREFIX'] = 'admin';
5+
$config['APP_PREFIX'] = 'Admin';
66

77
$config['DEFAULT_CLASS_NAME'] = 'CommonController';
88
$config['DEFAULT_METHOD_NAME'] = 'index';
9+
$config['CLASS_PREFIX'] = "\\Fc2blog\\Web\\Controller\\Admin\\";
910

1011
//$config['DIRECTORY_INDEX'] = 'admin.php';
1112

app/config/cron.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
$config['DEFAULT_CLASS_NAME'] = 'CommonController';
88
$config['DEFAULT_METHOD_NAME'] = 'index';
9-
9+
$config['CLASS_PREFIX'] = "\\Fc2blog\\Cli\\Controller\\Cron\\";
1010
$config['DEBUG'] = 4; // Debugの表示可否
1111

1212
return $config;

app/config/fc2_template.php

+54-54
Large diffs are not rendered by default.

app/config/routing.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*/
55

66
// 管理用のパラメータを設定する
7-
$request = Request::getInstance();
7+
$request = \Fc2blog\Web\Request::getInstance();
88
$paths = $request->getPaths();
9-
$argsc = Config::get('ARGS_CONTROLLER');
10-
$argsa = Config::get('ARGS_ACTION');
9+
$argsc = \Fc2blog\Config::get('ARGS_CONTROLLER');
10+
$argsa = \Fc2blog\Config::get('ARGS_ACTION');
1111

1212
if ($request->isArgs($argsc)) {
1313
$request->set($argsc, $request->get($argsc));

app/config/routing_test.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
*/
55

66
// 管理用のパラメータを設定する
7-
$request = Request::getInstance();
7+
$request = \Fc2blog\Web\Request::getInstance();
88
$path = $request->getPath(); // full path with out query args.
99
$paths = $request->getPaths(); // explode with `/`
1010
$query = $request->getQuery(); // query args
11-
$argsc = Config::get('ARGS_CONTROLLER');
12-
$argsa = Config::get('ARGS_ACTION');
11+
$argsc = \Fc2blog\Config::get('ARGS_CONTROLLER');
12+
$argsa = \Fc2blog\Config::get('ARGS_ACTION');
1313

1414
// argsa => method(action
1515
// argsc => class

app/config/routing_user.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
*/
55

66
// ユーザー用のパラメータを設定する
7-
$request = Request::getInstance();
7+
$request = \Fc2blog\Web\Request::getInstance();
88
$path = $request->getPath();
99
$paths = $request->getPaths();
1010
$query = $request->getQuery();
11-
$argsc = Config::get('ARGS_CONTROLLER');
12-
$argsa = Config::get('ARGS_ACTION');
11+
$argsc = \Fc2blog\Config::get('ARGS_CONTROLLER');
12+
$argsa = \Fc2blog\Config::get('ARGS_ACTION');
1313

1414
// blog_idの設定
1515
if (isset($paths[0]) && preg_match('/^[0-9a-zA-Z]+$/', $paths[0])) {

app/config/test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
$config = [];
44

5-
$config['APP_PREFIX'] = 'test';
5+
$config['APP_PREFIX'] = 'Test';
66

77
$config['DEFAULT_CLASS_NAME'] = 'CommonController';
88
$config['DEFAULT_METHOD_NAME'] = 'index';
9+
$config['CLASS_PREFIX'] = "\\Fc2blog\\Web\\Controller\\Test\\";
910

1011
$config['URL_REWRITE'] = true;
1112

app/config/user.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
$config = array();
44

5-
$config['APP_PREFIX'] = 'user';
5+
$config['APP_PREFIX'] = 'User';
66

77
$config['DEFAULT_CLASS_NAME'] = 'BlogsController';
88
$config['DEFAULT_METHOD_NAME'] = 'index';
9+
$config['CLASS_PREFIX'] = "\\Fc2blog\\Web\\Controller\\User\\";
910

1011
$config['URL_REWRITE'] = false;
1112

app/config_read_from_env.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
error_reporting(0);
1717
}
1818

19-
if (strlen((string)getenv("FC2_ERROR_ON_DISPLAY"))) {
19+
if ((string)getenv("FC2_ERROR_ON_DISPLAY") === 0) {
2020
ini_set('display_errors', '1');
2121
ini_set('display_startup_errors', '1');
2222
ini_set('html_errors', '1');

app/controller/test/test_controller.php

-8
This file was deleted.

app/core/bootstrap.php

+6-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
define('REQUEST_MICROTIME', microtime(true)); // 開始タイムスタンプ(ミリ秒含む)
4-
define('APP_DIR', realpath(dirname(__FILE__) . '/../') . '/'); // APPディレクトリのパス
4+
define('APP_DIR', realpath(__DIR__ . '/../') . '/'); // APPディレクトリのパス
55

66
// DBの接続ライブラリ
77
if (class_exists('mysqli')) {
@@ -10,42 +10,21 @@
1010
define('DB_CONNECT_LIB', 'PDO');
1111
}
1212

13-
// 設定クラス読み込み
14-
require(dirname(__FILE__) . '/config.php');
15-
1613
// ディレクトリ一覧読み込み
17-
Config::read(dirname(__FILE__) . '/../config/dir.php');
14+
\Fc2blog\Config::read(__DIR__ . '/../config/dir.php');
1815

1916
// 環境設定読み込み
20-
Config::read('env.php');
21-
22-
// 疑似Exitクラスの読み込み(テスト用)
23-
require_once(Config::get('CORE_DIR') . 'PseudoExit.php');
24-
25-
// リクエストクラスの読み込み
26-
require_once(Config::get('CORE_DIR') . 'request.php');
17+
\Fc2blog\Config::read('env.php');
2718

2819
// タイムゾーン設定
29-
date_default_timezone_set(Config::get('TIMEZONE'));
30-
31-
// Debugクラス
32-
require(Config::get('CORE_DIR') . 'debug.php');
33-
34-
// 共通関数群読み込み
35-
require(Config::get('CORE_DIR') . 'common_functions.php');
36-
37-
// Cookieクラス
38-
require_once(Config::get('CORE_DIR') . 'cookie.php');
39-
40-
// Sessionクラス
41-
require_once(Config::get('CORE_DIR') . 'session.php');
20+
date_default_timezone_set(\Fc2blog\Config::get('TIMEZONE'));
4221

4322
// 言語設定
4423
setLanguage();
4524

4625
// アプリの定数系読み込み
47-
Config::read('app.php');
26+
\Fc2blog\Config::read('app.php');
4827

4928
// 内部文字コードを設定
50-
mb_internal_encoding(Config::get('INTERNAL_ENCODING', 'UTF-8'));
29+
mb_internal_encoding(\Fc2blog\Config::get('INTERNAL_ENCODING', 'UTF-8'));
5130

app/core/common_functions.php

+31-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
// the file will be load by composer autoloader.
23

34
// lcfirst関数補完
45
if(function_exists('lcfirst') === false) {
@@ -16,7 +17,7 @@ function lcfirst($str) {
1617
* HTMLエスケープの短縮形
1718
*/
1819
function h($text){
19-
return htmlentities($text, ENT_QUOTES, Config::get('INTERNAL_ENCODING'));
20+
return htmlentities($text, ENT_QUOTES, \Fc2blog\Config::get('INTERNAL_ENCODING'));
2021
}
2122

2223

@@ -27,8 +28,8 @@ function t($text, $length=10, $etc='...'){
2728
if (!$length) {
2829
return '';
2930
}
30-
if (mb_strlen($text, Config::get('INTERNAL_ENCODING')) > $length) {
31-
return mb_substr($text, 0, $length, Config::get('INTERNAL_ENCODING')) . $etc;
31+
if (mb_strlen($text, \Fc2blog\Config::get('INTERNAL_ENCODING')) > $length) {
32+
return mb_substr($text, 0, $length, \Fc2blog\Config::get('INTERNAL_ENCODING')) . $etc;
3233
}
3334
return $text;
3435
}
@@ -100,59 +101,59 @@ function snakeCase($camel_case)
100101
}
101102

102103
/**
103-
* ルーティング用メソッド
104-
*/
105-
function getRouting(){
106-
require(Config::get('CONFIG_DIR') . Config::get('ROUTING')); // ルーティング設定を読み込み
104+
* ルーティング用メソッド
105+
*/
106+
function getRouting()
107+
{
108+
require(\Fc2blog\Config::get('CONFIG_DIR') . \Fc2blog\Config::get('ROUTING')); // ルーティング設定を読み込み
107109

108-
$request = Request::getInstance();
110+
$request = \Fc2blog\Web\Request::getInstance();
109111

110-
$defaultClass = Config::get('DEFAULT_CLASS_NAME');
111-
$defaultMethod = Config::get('DEFAULT_METHOD_NAME');
112-
$prefix = Config::get('APP_PREFIX');
112+
$defaultClass = \Fc2blog\Config::get('DEFAULT_CLASS_NAME');
113+
$defaultMethod = \Fc2blog\Config::get('DEFAULT_METHOD_NAME');
114+
$prefix = \Fc2blog\Config::get('APP_PREFIX');
115+
$classPrefix = \Fc2blog\Config::get('CLASS_PREFIX');
113116

114-
$denyClass = $prefix ? $prefix . 'Controller' : 'AppController';
115-
$denyMethod = array('process', 'display', 'fetch', 'set');
116-
$denyPattern = array('CommonController'=>array('install'));
117+
$denyClass = $prefix ? $prefix . 'Controller' : 'AppController';
118+
$denyMethod = array('process', 'display', 'fetch', 'set');
119+
$denyPattern = array('CommonController' => array('install'));
117120

118-
$argsc = Config::get('ARGS_CONTROLLER');
119-
$argsa = Config::get('ARGS_ACTION');
121+
$argsc = \Fc2blog\Config::get('ARGS_CONTROLLER');
122+
$argsa = \Fc2blog\Config::get('ARGS_ACTION');
120123

121124
$className = pascalCase(basename($request->get($argsc)));
122125
$className = $className ? $className . 'Controller' : $defaultClass;
123-
$classFile = Config::get('CONTROLLER_DIR') . ($prefix ? $prefix . '/' : '') . snakeCase($className) . '.php';
124126
$methodName = $request->get($argsa, $defaultMethod);
125127
$methodName = in_array($methodName, $denyMethod) ? $defaultMethod : $methodName;
126-
if ($className==$denyClass
127-
|| !is_file($classFile)
128-
|| (isset($denyPattern[$className]) && in_array($methodName, $denyPattern[$className]))
128+
if (
129+
$className == $denyClass ||
130+
(isset($denyPattern[$className]) && in_array($methodName, $denyPattern[$className]))
129131
) {
130132
$className = $defaultClass;
131-
$classFile = Config::get('CONTROLLER_DIR') . ($prefix ? $prefix . '/' : '') . snakeCase($className) . '.php';
132133
$methodName = $defaultMethod;
133134
}
134135

135-
return array($classFile, $className, $methodName);
136+
return array($classPrefix . $className, $methodName);
136137
}
137138

138139
/**
139140
* 言語設定
140141
*/
141142
function setLanguage($lang=null, $file='messages'){
142143
if ($lang==null) {
143-
$lang = Cookie::get('lang');
144+
$lang = \Fc2blog\Web\Cookie::get('lang');
144145
}
145146
if ($lang) {
146147
// 言語チェック
147-
if ($language=Config::get('LANGUAGES.' . $lang)) {
148-
Config::set('LANG', $lang);
149-
Config::set('LANGUAGE', $language);
148+
if ($language=\Fc2blog\Config::get('LANGUAGES.' . $lang)) {
149+
\Fc2blog\Config::set('LANG', $lang);
150+
\Fc2blog\Config::set('LANGUAGE', $language);
150151
}
151152
}
152153
// 多言語化対応
153-
putenv('LANG=' . Config::get('LANGUAGE'));
154-
setlocale(LC_ALL, Config::get('LANGUAGE'));
155-
bindtextdomain($file, Config::get('LOCALE_DIR'));
154+
putenv('LANG=' . \Fc2blog\Config::get('LANGUAGE'));
155+
setlocale(LC_ALL, \Fc2blog\Config::get('LANGUAGE'));
156+
bindtextdomain($file, \Fc2blog\Config::get('LOCALE_DIR'));
156157
textdomain($file);
157158
}
158159

@@ -171,7 +172,7 @@ function is_countable ($var)
171172
function getServerUrl()
172173
{
173174
$url = (empty($_SERVER["HTTPS"])) ? 'http://' : 'https://';
174-
$url .= Config::get('DOMAIN');
175+
$url .= \Fc2blog\Config::get('DOMAIN');
175176

176177
return $url;
177178
}

app/include/admin_index_include.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once(__DIR__ . '/../vendor/autoload.php');
6+
27
require(__DIR__ . '/config_loading_include.php');
38

4-
Config::read('admin.php'); // Admin用の環境設定読み込み
9+
\Fc2blog\Config::read('admin.php'); // Admin用の環境設定読み込み
510

6-
Debug::log('Controller Action', false, 'system', __FILE__, __LINE__);
11+
\Fc2blog\Debug::log('Controller Action', false, 'system', __FILE__, __LINE__);
712

8-
list($classFile, $className, $methodName) = getRouting();
9-
require($classFile);
13+
list($className, $methodName) = getRouting();
1014
$controller = new $className($methodName);
1115

12-
Debug::output($controller); // Debug用の出力
16+
\Fc2blog\Debug::output($controller); // Debug用の出力

app/include/admin_install_include.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once(__DIR__ . '/../vendor/autoload.php');
6+
27
require(__DIR__ . '/config_loading_include.php');
38

4-
Config::read('admin.php'); // Admin用の環境設定読み込み
9+
\Fc2blog\Config::read('admin.php'); // Admin用の環境設定読み込み
510

6-
require(Config::get('CONTROLLER_DIR') . 'admin/common_controller.php');
7-
$controller = new CommonController('install');
11+
$controller = new \Fc2blog\Web\Controller\Admin\CommonController('install');

app/include/for_unit_test_index_include.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once(__DIR__ . '/../vendor/autoload.php');
6+
27
require(__DIR__ . '/config_loading_include.php');
38

49
// test endpoint work in only DEBUG mode.
@@ -12,12 +17,11 @@
1217
exit;
1318
}
1419

15-
Config::read('test.php'); // test用の環境設定読み込み
20+
\Fc2blog\Config::read('test.php'); // test用の環境設定読み込み
1621

17-
Debug::log('Controller Action', false, 'system', __FILE__, __LINE__);
22+
\Fc2blog\Debug::log('Controller Action', false, 'system', __FILE__, __LINE__);
1823

19-
list($classFile, $className, $methodName) = getRouting();
20-
require($classFile);
24+
list($className, $methodName) = getRouting();
2125
$controller = new $className($methodName);
2226

23-
Debug::output($controller);
27+
\Fc2blog\Debug::output($controller);

app/include/index_include.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once(__DIR__ . '/../vendor/autoload.php');
6+
27
require(__DIR__ . '/config_loading_include.php');
38

4-
Config::read('user.php'); // User用の環境設定読み込み
9+
\Fc2blog\Config::read('user.php'); // User用の環境設定読み込み
510

6-
Debug::log('Controller Action', false, 'system', __FILE__, __LINE__);
11+
\Fc2blog\Debug::log('Controller Action', false, 'system', __FILE__, __LINE__);
712

8-
list($classFile, $className, $methodName) = getRouting();
9-
require($classFile);
13+
list($className, $methodName) = getRouting();
1014
$controller = new $className($methodName);
1115

12-
Debug::output($controller); // Debug用の出力
16+
\Fc2blog\Debug::output($controller); // Debug用の出力

0 commit comments

Comments
 (0)