22
33use Str ;
44use Event ;
5+ use Cache ;
6+ use Bundle ;
57use Request ;
68use FilesystemIterator ;
79use Feather \Core \Gear ;
810use InvalidArgumentException ;
9- use Feather \Components \Foundation \ Component ;
11+ use Feather \Components \Foundation ;
1012
11- class Manager extends Component {
13+ class Manager extends Foundation \ Component {
1214
1315 /**
1416 * Registered Gears.
@@ -24,6 +26,41 @@ class Manager extends Component {
2426 */
2527 public $ started = array ();
2628
29+ /**
30+ * Bootstraps the Gears, loads from database and registers with the manager.
31+ *
32+ * @param Feather\Components\Foundation\Application $feather
33+ * @return void
34+ */
35+ public function __construct (Foundation \Application $ feather )
36+ {
37+ parent ::__construct ($ feather );
38+
39+ Cache::forget ('gears ' );
40+
41+ $ manager = $ this ;
42+
43+ return Cache::sear ('gears ' , function () use ($ manager )
44+ {
45+ foreach (Gear::enabled () as $ gear )
46+ {
47+ Bundle::register ($ gear ->identifier , array (
48+ 'location ' => 'path: ' . path ('gears ' ) . $ gear ->identifier ,
49+ 'handles ' => trim (str_replace ('(:feather) ' , Bundle::option ('feather ' , 'handles ' ), $ gear ->handles ), '/ ' ),
50+ 'auto ' => (bool ) $ gear ->auto ,
51+ 'autoloads ' => (array ) json_decode ($ gear ->loads )
52+ ));
53+
54+ if ($ gear ->auto )
55+ {
56+ Bundle::start ($ gear ->identifier );
57+ }
58+
59+ $ manager ->register ($ gear );
60+ }
61+ });
62+ }
63+
2764 /**
2865 * Register a Gear with the manager.
2966 *
@@ -115,6 +152,8 @@ public function start($gear)
115152 if (class_exists ($ class ))
116153 {
117154 $ this ->started [$ gear ][$ name ] = new $ class ;
155+
156+ $ this ->started [$ gear ][$ name ]->application ($ this ->feather );
118157 }
119158 }
120159 }
0 commit comments