2727use PHPCR \Shell \Event \PhpcrShellEvents ;
2828use PHPCR \Shell \Subscriber ;
2929use PHPCR \Shell \Console \Command \Phpcr \PhpcrShellCommand ;
30+ use PHPCR \Shell \Config \Profile ;
31+ use PHPCR \Shell \Transport \TransportRegistry ;
3032
3133/**
3234 * Main application for PHPCRSH
@@ -43,9 +45,9 @@ class ShellApplication extends Application
4345 protected $ initialized ;
4446
4547 /**
46- * @var \Symfony\Component\Console\Input\InputInterface
48+ * @var boolean
4749 */
48- protected $ sessionInput ;
50+ protected $ showUnsupported = false ;
4951
5052 /**
5153 * Constructor - name and version inherited from SessionApplication
@@ -55,18 +57,39 @@ class ShellApplication extends Application
5557 public function __construct ($ name = 'UNKNOWN ' , $ version = 'UNKNOWN ' )
5658 {
5759 parent ::__construct ($ name , $ version );
60+ $ this ->profile = new Profile ();
5861 $ this ->dispatcher = new EventDispatcher ();
62+ $ this ->transportRegistry = new TransportRegistry ();
63+ $ this ->registerTransports ();
64+ $ this ->registerEventListeners ();
5965 }
6066
6167 /**
62- * The SessionInput is the input used to intialize the shell.
63- * It contains the connection parameters.
68+ * Initialize the supported transports.
6469 *
65- * @param \Symfony\Component\Console\Input\InputInterface $input
70+ * @access private
6671 */
67- public function setSessionInput ( InputInterface $ input )
72+ protected function registerTransports ( )
6873 {
69- $ this ->sessionInput = $ input ;
74+ $ transports = array (
75+ new \PHPCR \Shell \Transport \Transport \DoctrineDbal ($ this ->profile ),
76+ new \PHPCR \Shell \Transport \Transport \Jackrabbit ($ this ->profile ),
77+ );
78+
79+ foreach ($ transports as $ transport ) {
80+ $ this ->transportRegistry ->register ($ transport );
81+ }
82+ }
83+
84+ /**
85+ * If true, show all commands, even if they are unsupported by the
86+ * transport.
87+ *
88+ * @param boolean $boolean
89+ */
90+ public function setShowUnsupported ($ boolean )
91+ {
92+ $ this ->showUnsupported = $ boolean ;
7093 }
7194
7295 /**
@@ -82,15 +105,8 @@ public function init()
82105 return ;
83106 }
84107
85- if (null === $ this ->sessionInput ) {
86- throw new \RuntimeException (
87- 'sessionInput has not been set. '
88- );
89- }
90-
91108 $ this ->registerHelpers ();
92109 $ this ->registerCommands ();
93- $ this ->registerEventListeners ();
94110
95111 $ event = new ApplicationInitEvent ($ this );
96112 $ this ->dispatcher ->dispatch (PhpcrShellEvents::APPLICATION_INIT , $ event );
@@ -103,7 +119,7 @@ public function init()
103119 */
104120 private function registerHelpers ()
105121 {
106- $ phpcrHelper = new PhpcrHelper ($ this ->sessionInput );
122+ $ phpcrHelper = new PhpcrHelper ($ this ->transportRegistry , $ this -> profile );
107123
108124 $ helpers = array (
109125 new ConfigHelper (),
@@ -207,9 +223,11 @@ private function registerCommands()
207223
208224 private function registerEventListeners ()
209225 {
226+ $ this ->dispatcher ->addSubscriber (new Subscriber \ProfileFromSessionInputSubscriber ());
227+
210228 $ this ->dispatcher ->addSubscriber (new Subscriber \ConfigInitSubscriber ());
211229 $ this ->dispatcher ->addSubscriber (new Subscriber \ExceptionSubscriber ());
212- $ this ->dispatcher ->addSubscriber (new Subscriber \AliasSubscriber ($ this ->getHelperSet ()-> get ( ' config ' ) ));
230+ $ this ->dispatcher ->addSubscriber (new Subscriber \AliasSubscriber ($ this ->getHelperSet ()));
213231 }
214232
215233 /**
@@ -286,13 +304,17 @@ public function renderException($exception, $output)
286304 public function add (Command $ command )
287305 {
288306 if ($ command instanceof PhpcrShellCommand) {
289- $ showUnsupported = $ this ->sessionInput ->getOption ('unsupported ' );
290-
291- if ($ showUnsupported || $ command ->isSupported ($ this ->getHelperSet ()->get ('repository ' ))) {
307+ if ($ this ->showUnsupported || $ command ->isSupported ($ this ->getHelperSet ()->get ('repository ' ))) {
292308 parent ::add ($ command );
293309 }
294310 } else {
295311 parent ::add ($ command );
296312 }
297313 }
314+
315+ public function dispatchProfileInitEvent (InputInterface $ sessionInput , OutputInterface $ output )
316+ {
317+ $ event = new Event \ProfileInitEvent ($ this ->profile , $ sessionInput , $ output );
318+ $ this ->dispatcher ->dispatch (PhpcrShellEvents::PROFILE_INIT , $ event );
319+ }
298320}
0 commit comments