|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the [code] |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) [year] [author] |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Plugin\[code]\ServiceProvider; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; |
|
15
|
|
|
use Monolog\Handler\FingersCrossedHandler; |
|
16
|
|
|
use Monolog\Handler\RotatingFileHandler; |
|
17
|
|
|
use Monolog\Logger; |
|
18
|
|
|
use Plugin\[code]\Form\Type\[code]ConfigType; |
|
19
|
|
|
use Silex\Application as BaseApplication; |
|
20
|
|
|
use Silex\ServiceProviderInterface; |
|
21
|
|
|
|
|
22
|
|
|
class [code]ServiceProvider implements ServiceProviderInterface |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
public function register(BaseApplication $app) |
|
26
|
|
|
{ |
|
27
|
|
|
// プラグイン用設定画面 |
|
28
|
|
|
$app->match('/'.$app['config']['admin_route'].'/plugin/[code]/config', 'Plugin\[code]\Controller\ConfigController::index')->bind('plugin_[code]_config'); |
|
29
|
|
|
|
|
30
|
|
|
// 独自コントローラ |
|
31
|
|
|
$app->match('/plugin/[lower_code]/hello', 'Plugin\[code]\Controller\[code]Controller::index')->bind('plugin_[code]_hello'); |
|
32
|
|
|
|
|
33
|
|
|
// Form |
|
34
|
|
|
$app['form.types'] = $app->share($app->extend('form.types', function ($types) use ($app) { |
|
35
|
|
|
$types[] = new [code]ConfigType(); |
|
36
|
|
|
|
|
37
|
|
|
return $types; |
|
38
|
|
|
})); |
|
39
|
|
|
|
|
40
|
|
|
// Repository |
|
41
|
|
|
|
|
42
|
|
|
// Service |
|
43
|
|
|
|
|
44
|
|
|
// メッセージ登録 |
|
45
|
|
|
// $file = __DIR__ . '/../Resource/locale/message.' . $app['locale'] . '.yml'; |
|
46
|
|
|
// $app['translator']->addResource('yaml', $file, $app['locale']); |
|
47
|
|
|
|
|
48
|
|
|
// load config |
|
49
|
|
|
// プラグイン独自の定数はconfig.ymlの「const」パラメータに対して定義し、$app['[lower_code]config']['定数名']で利用可能 |
|
50
|
|
|
// if (isset($app['config']['[code]']['const'])) { |
|
51
|
|
|
// $config = $app['config']; |
|
52
|
|
|
// $app['[lower_code]config'] = $app->share(function () use ($config) { |
|
53
|
|
|
// return $config['[code]']['const']; |
|
54
|
|
|
// }); |
|
55
|
|
|
// } |
|
56
|
|
|
|
|
57
|
|
|
// ログファイル設定 |
|
58
|
|
|
$app['monolog.logger.[lower_code]'] = $app->share(function ($app) { |
|
59
|
|
|
|
|
60
|
|
|
$logger = new $app['monolog.logger.class']('[lower_code]'); |
|
61
|
|
|
|
|
62
|
|
|
$filename = $app['config']['root_dir'].'/app/log/[lower_code].log'; |
|
63
|
|
|
$RotateHandler = new RotatingFileHandler($filename, $app['config']['log']['max_files'], Logger::INFO); |
|
64
|
|
|
$RotateHandler->setFilenameFormat( |
|
65
|
|
|
'[lower_code]_{date}', |
|
66
|
|
|
'Y-m-d' |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$logger->pushHandler( |
|
70
|
|
|
new FingersCrossedHandler( |
|
71
|
|
|
$RotateHandler, |
|
72
|
|
|
new ErrorLevelActivationStrategy(Logger::ERROR), |
|
73
|
|
|
0, |
|
74
|
|
|
true, |
|
75
|
|
|
true, |
|
76
|
|
|
Logger::INFO |
|
77
|
|
|
) |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
return $logger; |
|
81
|
|
|
}); |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function boot(BaseApplication $app) |
|
86
|
|
|
{ |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|