1 | <?php |
||
34 | class Ssh extends \Thread implements ConsoleInterface |
||
35 | { |
||
36 | |||
37 | /** |
||
38 | * appserver.io written in ASCI art. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected static $logo = ' _ |
||
43 | ____ _____ ____ ________ ______ _____ _____(_)___ |
||
44 | / __ `/ __ \/ __ \/ ___/ _ \/ ___/ | / / _ \/ ___/ / __ \ |
||
45 | / /_/ / /_/ / /_/ (__ ) __/ / | |/ / __/ / / / /_/ / |
||
46 | \__,_/ .___/ .___/____/\___/_/ |___/\___/_(_)/_/\____/ |
||
47 | /_/ /_/ |
||
48 | |||
49 | '; |
||
50 | |||
51 | /** |
||
52 | * Initialize and start the management console. |
||
53 | * |
||
54 | * @param \AppserverIo\Psr\ApplicationServer\ApplicationServerInterface $applicationServer The reference to the server |
||
55 | * |
||
56 | * @return void |
||
57 | */ |
||
58 | public function __construct($applicationServer) |
||
59 | { |
||
60 | $this->applicationServer = $applicationServer; |
||
61 | $this->start(PTHREADS_INHERIT_ALL); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Return's the service name. |
||
66 | * |
||
67 | * @return string The service name |
||
68 | */ |
||
69 | public function getName() |
||
70 | { |
||
71 | return 'console'; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Shutdown handler that checks for fatal/user errors. |
||
76 | * |
||
77 | * @return void |
||
78 | */ |
||
79 | public function shutdown() |
||
80 | { |
||
81 | // check if there was a fatal error caused shutdown |
||
82 | if ($lastError = error_get_last()) { |
||
83 | // initialize type + message |
||
84 | $type = 0; |
||
85 | $message = ''; |
||
86 | // extract the last error values |
||
87 | extract($lastError); |
||
88 | // query whether we've a fatal/user error |
||
89 | if ($type === E_ERROR || $type === E_USER_ERROR) { |
||
90 | echo $message . PHP_EOL; |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Stop the console and closes all connections. |
||
97 | * |
||
98 | * @return void |
||
99 | */ |
||
100 | public function stop() |
||
101 | { |
||
102 | $this->kill(); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * The thread's run() method that runs asynchronously. |
||
107 | * |
||
108 | * @return void |
||
109 | * @link http://www.php.net/manual/en/thread.run.php |
||
110 | */ |
||
111 | public function run() |
||
112 | { |
||
113 | |||
114 | // register a shutdown handler for controlled shutdown |
||
115 | register_shutdown_function(array(&$this, 'shutdown')); |
||
116 | |||
117 | // we need the autloader again |
||
118 | require SERVER_AUTOLOADER; |
||
119 | |||
120 | require_once 'vendor/fpoirotte/pssht/src/CLI.php'; |
||
121 | |||
122 | main(); |
||
123 | } |
||
124 | } |
||
125 |