1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
<?php
/**
* @author stev leibelt <artodeto@bazzline.net>
* @since 2014-08-17
*/
/**
* Class AbstractApplication
* This class is doing a lot. See it as class that is the
* - Application
* - Factory
* - ServiceLocator
*/
abstract class AbstractApplication
{
/**
* @var array
*/
private $arguments = array();
/**
* @var array
*/
private $chatConfiguration = array();
/**
* @var array
*/
private $channels = array();
/**
* @var array
*/
private $instancePool;
/**
* @var array
*/
private $roles = array();
/**
* @var array
*/
private $users = array();
//begin of command
/**
* @return Command_Backup
*/
public function getBackupCommand()
{
if ($this->isNotInInstancePool('command_backup')) {
$command = new Command_Backup();
$command->setFilesystem($this->getFilesystem());
$command->setInput($this->getInput());
$command->setPathConfiguration($this->getPathConfiguration());
$command->setOutput($this->getOutput());
$this->setToInstancePool('command_backup', $command);
}
return $this->getFromInstancePool('command_backup');
}
/**
* @return Command_Channel
*/
public function getChannelCommand()
{
if ($this->isNotInInstancePool('channel_command')) {
$command = new Command_Channel();
$command->setApplication($this);
$command->setFilesystem($this->getFilesystem());
$command->setInput($this->getInput());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'channel_command',
$command
);
}
return $this->getFromInstancePool('channel_command');
}
/**
* @return Command_Channel_Add
*/
public function getChannelAddCommand()
{
if ($this->isNotInInstancePool('channel_add_command')) {
$command = new Command_Channel_Add();
$command->setChannelFile($this->getChannelFile());
$command->setChannels($this->getChannels());
$command->setInput($this->getInput());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'channel_add_command',
$command
);
}
return $this->getFromInstancePool('channel_add_command');
}
/**
* @return Command_Channel_Delete
*/
public function getChannelDeleteCommand()
{
if ($this->isNotInInstancePool('channel_delete_command')) {
$command = new Command_Channel_Delete();
$command->setChannelFile($this->getChannelFile());
$command->setChannels($this->getChannels());
$command->setInput($this->getInput());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'channel_delete_command',
$command
);
}
return $this->getFromInstancePool('channel_delete_command');
}
/**
* @return Command_Channel_Edit
*/
public function getChannelEditCommand()
{
if ($this->isNotInInstancePool('channel_edit_command')) {
$command = new Command_Channel_Edit();
$command->setChannelFile($this->getChannelFile());
$command->setChannels($this->getChannels());
$command->setInput($this->getInput());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'channel_edit_command',
$command
);
}
return $this->getFromInstancePool('channel_edit_command');
}
/**
* @return Command_Channel_List
*/
public function getChannelListCommand()
{
if ($this->isNotInInstancePool('channel_list_command')) {
$command = new Command_Channel_List();
$command->setChannelFile($this->getChannelFile());
$command->setChannels($this->getChannels());
$command->setInput($this->getInput());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'channel_list_command',
$command
);
}
return $this->getFromInstancePool('channel_list_command');
}
/**
* @return Command_Install
*/
public function getInstallCommand()
{
if ($this->isNotInInstancePool('install_command')) {
$command = new Command_Install();
$command->setFilesystem($this->getFilesystem());
$command->setInput($this->getInput());
$command->setPathConfiguration($this->getPathConfiguration());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'install_command',
$command
);
}
return $this->getFromInstancePool('install_command');
}
/**
* @return Command_Restore
*/
public function getRestoreCommand()
{
if ($this->isNotInInstancePool('restore_command')) {
$command = new Command_Restore();
$command->setFilesystem($this->getFilesystem());
$command->setInput($this->getInput());
$command->setPathConfiguration($this->getPathConfiguration());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'restore_command',
$command
);
}
return $this->getFromInstancePool('restore_command');
}
/**
* @return Command_Upgrade
*/
public function getUpgradeCommand()
{
if ($this->isNotInInstancePool('upgrade_command')) {
$command = new Command_Upgrade();
$command->setApplication($this);
$command->setChangeLog($this->getFile($this->getPathConfiguration()->getChangeLogFilePath()));
$command->setFilesystem($this->getFilesystem());
$command->setInput($this->getInput());
$command->setPathConfiguration($this->getPathConfiguration());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'upgrade_command',
$command
);
}
return $this->getFromInstancePool('upgrade_command');
}
/**
* @return Command_User
*/
public function getUserCommand()
{
if ($this->isNotInInstancePool('user_command')) {
$command = new Command_User();
$command->setApplication($this);
$command->setFilesystem($this->getFilesystem());
$command->setInput($this->getInput());
$command->setPathConfiguration($this->getPathConfiguration());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'user_command',
$command
);
}
return $this->getFromInstancePool('user_command');
}
/**
* @return Command_User_Add
*/
public function getUserAddCommand()
{
if ($this->isNotInInstancePool('user_add_command')) {
$command = new Command_User_Add();
$command->setChannels($this->getChannels());
$command->setOutput($this->getOutput());
$command->setRoles($this->getRoles());
$command->setUserFile($this->getUserFile());
$command->setUsers($this->getUsers());
$this->setToInstancePool(
'user_add_command',
$command
);
}
return $this->getFromInstancePool('user_add_command');
}
/**
* @return Command_User_Edit
*/
public function getUserEditCommand()
{
if ($this->isNotInInstancePool('user_edit_command')) {
$command = new Command_User_Edit();
$command->setChannels($this->getChannels());
$command->setInput($this->getInput());
$command->setOutput($this->getOutput());
$command->setRoles($this->getRoles());
$command->setUserFile($this->getUserFile());
$command->setUsers($this->getUsers());
$this->setToInstancePool(
'user_edit_command',
$command
);
}
return $this->getFromInstancePool('user_edit_command');
}
/**
* @return Command_User_Delete
*/
public function getUserDeleteCommand()
{
if ($this->isNotInInstancePool('user_delete_command')) {
$command = new Command_User_Delete();
$command->setChannels($this->getChannels());
$command->setInput($this->getInput());
$command->setOutput($this->getOutput());
$command->setRoles($this->getRoles());
$command->setUserFile($this->getUserFile());
$command->setUsers($this->getUsers());
$this->setToInstancePool(
'user_delete_command',
$command
);
}
return $this->getFromInstancePool('user_delete_command');
}
/**
* @return Command_User_List
*/
public function getUserListCommand()
{
if ($this->isNotInInstancePool('user_list_command')) {
$command = new Command_User_List();
$command->setChannels($this->getChannels());
$command->setInput($this->getInput());
$command->setOutput($this->getOutput());
$command->setRoles($this->getRoles());
$command->setUserFile($this->getUserFile());
$command->setUsers($this->getUsers());
$this->setToInstancePool(
'user_list_command',
$command
);
}
return $this->getFromInstancePool('user_list_command');
}
/**
* @return Command_VerifyInstallation
*/
public function getVerifyInstallationCommand()
{
if ($this->isNotInInstancePool('validate_installation_command')) {
$command = new Command_VerifyInstallation();
$command->setApplication($this);
$command->setInput($this->getInput());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'validate_installation_command',
$command
);
}
return $this->getFromInstancePool('validate_installation_command');
}
/**
* @return Command_VerifyInstallation_LocalFiles
*/
public function getVerifyInstallationLocalFilesCommand()
{
if ($this->isNotInInstancePool('validate_installation_local_files_command')) {
$command = new Command_VerifyInstallation_LocalFiles();
$command->setApplication($this);
$command->setFilesystem($this->getFilesystem());
$command->setInput($this->getInput());
$command->setPathConfiguration($this->getPathConfiguration());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'validate_installation_local_files_command',
$command
);
}
return $this->getFromInstancePool('validate_installation_local_files_command');
}
/**
* @return Command_VerifyInstallation_Version
*/
public function getVerifyInstallationVersionCommand()
{
if ($this->isNotInInstancePool('validate_installation_version_command')) {
$command = new Command_VerifyInstallation_Version();
$command->setApplication($this);
$command->setFilesystem($this->getFilesystem());
$command->setInput($this->getInput());
$command->setPathConfiguration($this->getPathConfiguration());
$command->setOutput($this->getOutput());
$this->setToInstancePool(
'validate_installation_version_command',
$command
);
}
return $this->getFromInstancePool('validate_installation_version_command');
}
//end of command
//begin of file
/**
* @return File
*/
public function getChannelFile()
{
if ($this->isNotInInstancePool('channel_file')) {
$this->setToInstancePool(
'channel_file',
$this->getFile(
$this->getPathConfiguration()->getChatChannelsFilePath()
)
);
}
return $this->getFromInstancePool('channel_file');
}
/**
* @return File
*/
public function getUserFile()
{
if ($this->isNotInInstancePool('user_file')) {
$this->setToInstancePool(
'user_file',
$this->getFile(
$this->getPathConfiguration()->getChatUsersFilePath()
)
);
}
return $this->getFromInstancePool('user_file');
}
//end of file
/**
* @return array
*/
public function getChannels()
{
if (empty($this->channels)) {
$this->setPropertyFromFile(
'channels',
'channels',
$this->getPathConfiguration()->getChatChannelsFilePath()
);
}
return $this->channels;
}
/**
* @return array
*/
public function getChatConfiguration()
{
if (empty($this->chatConfiguration)) {
$this->setPropertyFromFile(
'chatConfiguration',
'config',
$this->getPathConfiguration()->getChatConfigurationFilePath()
);
}
return $this->chatConfiguration;
}
/**
* @return string
*/
public function getCurrentVersion()
{
return require $this->getPathConfiguration()->getChatVersionFilePath();
}
/**
* @return string
*/
public function getExampleVersion()
{
return require $this->getPathConfiguration()->getExampleVersionFilePath();
}
/**
* @param null|string $path
* @return File
*/
public function getFile($path = null)
{
return new File($path);
}
/**
* @return Filesystem
*/
public function getFilesystem()
{
if ($this->isNotInInstancePool('filesystem')) {
$filesystem = new Filesystem();
$this->setToInstancePool('filesystem', $filesystem);
}
return $this->getFromInstancePool('filesystem');
}
/**
* @return Input
*/
public function getInput()
{
if ($this->isNotInInstancePool('input')) {
$this->setToInstancePool(
'input',
new Input($this->getString(), $this->arguments)
);
}
return $this->getFromInstancePool('input');
}
/**
* @return Output
*/
public function getOutput()
{
if ($this->isNotInInstancePool('output')) {
$this->setToInstancePool(
'output',
new Output()
);
}
return $this->getFromInstancePool('output');
}
/**
* @return Configuration_Path
*/
public function getPathConfiguration()
{
if ($this->isNotInInstancePool('configuration_path')) {
$configuration = new Configuration_Path('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
$this->setToInstancePool('configuration_path', $configuration);
}
return $this->getFromInstancePool('configuration_path');
}
/**
* @return array
*/
public function getRoles()
{
$this->getChatConfiguration();
if (empty($this->roles)) {
if (defined('AJAX_CHAT_GUEST')) {
$this->roles = array(
AJAX_CHAT_GUEST => 'AJAX_CHAT_GUEST',
AJAX_CHAT_USER => 'AJAX_CHAT_USER',
AJAX_CHAT_MODERATOR => 'AJAX_CHAT_MODERATOR',
AJAX_CHAT_ADMIN => 'AJAX_CHAT_ADMIN',
AJAX_CHAT_CHATBOT => 'AJAX_CHAT_CHATBOT',
AJAX_CHAT_CUSTOM => 'AJAX_CHAT_CUSTOM',
AJAX_CHAT_BANNED => 'AJAX_CHAT_BANNED'
);
}
}
return $this->roles;
}
/**
* @return String
*/
public function getString()
{
if ($this->isNotInInstancePool('string')) {
$this->setToInstancePool('string', new String());
}
return $this->getFromInstancePool('string');
}
/**
* @return array
*/
public function getUsers()
{
//@todo - fix this damn call, if we remove this the needed constants are not defined
$this->getChatConfiguration();
if (empty($this->users)) {
$this->setPropertyFromFile(
'users',
'users',
$this->getPathConfiguration()->getChatUsersFilePath()
);
}
return $this->users;
}
/**
* @param array $arguments
*/
public function setArguments(array $arguments)
{
$this->arguments = $arguments;
}
/**
* @param string $key
* @return mixed
*/
private function getFromInstancePool($key)
{
return $this->instancePool[$key];
}
/**
* @param string $key
* @return bool
*/
private function isNotInInstancePool($key)
{
return (!(isset($this->instancePool[$key])));
}
/**
* @param string $propertyName
* @param string $fileValueName
* @param string $filePath
* @throws Exception
*/
private function setPropertyFromFile($propertyName, $fileValueName, $filePath)
{
if (!is_file($filePath)) {
throw new Exception(
'provided file path is not valid: ' . $filePath
);
}
require $filePath;
$this->$propertyName = $$fileValueName;
}
/**
* @param string $key
* @param mixed $value
*/
private function setToInstancePool($key, $value)
{
$this->instancePool[$key] = $value;
}
}
|