File tree Expand file tree Collapse file tree 4 files changed +50
-6
lines changed Expand file tree Collapse file tree 4 files changed +50
-6
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Class App
5+ *
6+ * @package \\${NAMESPACE}
7+ */
8+ class App
9+ {
10+ protected static $ registries = [];
11+
12+ public static function bind ($ key , $ value )
13+ {
14+ static ::$ registries [$ key ] = $ value ;
15+ }
16+
17+ public static function get ($ key )
18+ {
19+ if (!array_key_exists ($ key , static ::$ registries ))
20+ {
21+ throw new Exception ("No {$ key } is bound in the container. " );
22+ }
23+
24+ return static ::$ registries [$ key ];
25+ }
26+
27+ }
Original file line number Diff line number Diff line change 11<?php
22
3- $ app = [];
4-
5- // 获取配置
6- $ app ['config ' ] = require ROOT . DS . 'config.php ' ;
73require 'functions.php ' ;
84
95/*
2016// 类自动加载方法,其他的文件不会自动引入,如function.php
2117require __DIR__ . '/.. ' . '/vendor/autoload.php ' ;
2218
23- $ app ['database ' ] = new QueryBuilder (
24- Connection::make ($ app ['config ' ]['database ' ])
19+ // $app = [];
20+
21+ // 获取配置
22+ // $app['config'] = require ROOT . DS . 'config.php';
23+
24+ // 这里使用依赖注入优化上边的数组方法
25+ App::bind ('config ' , require ROOT . DS . 'config.php ' );
26+
27+ /*
28+ $app['database'] = new QueryBuilder(
29+ Connection::make(App::get('config')['database'])
2530);
31+ */
32+ App::bind ('database ' , new QueryBuilder (
33+ Connection::make (App::get ('config ' )['database ' ])
34+ ));
Original file line number Diff line number Diff line change 66$ baseDir = dirname ($ vendorDir );
77
88return array (
9+ 'App ' => $ baseDir . '/core/App.php ' ,
10+ 'ComposerAutoloaderInit83cb48187cf44a304a7a6be5e700ede3 ' => $ vendorDir . '/composer/autoload_real.php ' ,
11+ 'Composer \\Autoload \\ClassLoader ' => $ vendorDir . '/composer/ClassLoader.php ' ,
12+ 'Composer \\Autoload \\ComposerStaticInit83cb48187cf44a304a7a6be5e700ede3 ' => $ vendorDir . '/composer/autoload_static.php ' ,
913 'Connection ' => $ baseDir . '/core/database/Connection.php ' ,
1014 'QueryBuilder ' => $ baseDir . '/core/database/QueryBuilder.php ' ,
1115 'Request ' => $ baseDir . '/core/Request.php ' ,
Original file line number Diff line number Diff line change 77class ComposerStaticInit83cb48187cf44a304a7a6be5e700ede3
88{
99 public static $ classMap = array (
10+ 'App ' => __DIR__ . '/../.. ' . '/core/App.php ' ,
11+ 'ComposerAutoloaderInit83cb48187cf44a304a7a6be5e700ede3 ' => __DIR__ . '/.. ' . '/composer/autoload_real.php ' ,
12+ 'Composer \\Autoload \\ClassLoader ' => __DIR__ . '/.. ' . '/composer/ClassLoader.php ' ,
13+ 'Composer \\Autoload \\ComposerStaticInit83cb48187cf44a304a7a6be5e700ede3 ' => __DIR__ . '/.. ' . '/composer/autoload_static.php ' ,
1014 'Connection ' => __DIR__ . '/../.. ' . '/core/database/Connection.php ' ,
1115 'QueryBuilder ' => __DIR__ . '/../.. ' . '/core/database/QueryBuilder.php ' ,
1216 'Request ' => __DIR__ . '/../.. ' . '/core/Request.php ' ,
You can’t perform that action at this time.
0 commit comments