forked from catx23/xamiro
/
Bootstrap.php
executable file
·1667 lines (1396 loc) · 42.3 KB
/
Bootstrap.php
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @version 0.1.0
*
* @author https://github.com/mc007
* @license : GPL v2. http://www.gnu.org/licenses/gpl-2.0.html
* @package xapp
*/
/***
* Processing Flag 'Load Client Resources' instructs the bootstrapper to gather a Dojo's application client side
* resource files.
*/
define('XAPP_BOOTSTRAP_LOAD_CLIENT_RESOURCES', 55022);
/***
* Processing Flag 'Load Plugin Resources' instructs the bootstrapper to gather a client side plugin resources
*/
define('XAPP_BOOTSTRAP_LOAD_PLUGIN_RESOURCES', 55023);
/***
* Processing Flag 'Create resource renderer' instructs the bootstrapper to create a resource renderer. This is needed
* when rendering a Dojo application
*/
define('XAPP_BOOTSTRAP_CREATE_RESOURCE_RENDERER', 55024);
/***
* Processing Flag 'Register server plugins ' instructs the bootstrapper to register plugins on the RPC server
*/
define('XAPP_BOOTSTRAP_REGISTER_SERVER_PLUGINS', 55025);
/***
* Processing Flag 'Setup XApp' instructs the bootstrapper to setup xapp-php core, which handles output stream and some debugging options
*/
define('XAPP_BOOTSTRAP_SETUP_XAPP', 55026);
/***
* Processing Flag 'Setup RPC Server' instructs the bootstrapper to create our standard RPC server
*/
define('XAPP_BOOTSTRAP_SETUP_RPC', 55027);
/***
* Processing Flag 'Setup File Service' instructs the bootstrapper to create our standard file service
*/
define('XAPP_BOOTSTRAP_SETUP_XFILE', 55028);
/***
* Processing Flag 'Setup Services' instructs the bootstrapper to register a number of services on the RPC server
*/
define('XAPP_BOOTSTRAP_SETUP_SERVICES', 55029);
/***
* Processing Flag 'Setup Gateway'
*/
define('XAPP_BOOTSTRAP_SETUP_GATEWAY', 55030);
/***
* Processing Flag 'Setup Logger'
*/
define('XAPP_BOOTSTRAP_SETUP_LOGGER', 55031);
/***
* Processing Flag 'Setup Console'
*/
define('XAPP_BOOTSTRAP_SETUP_CONSOLE', 55032);
/***
* Processing Flag 'Setup Store'
*/
define('XAPP_BOOTSTRAP_SETUP_STORE', 55033);
/***
* Processing Flag 'Render Head'
*/
define('XAPP_BOOTSTRAP_RENDER_HEAD', 55034);
/***
* Processing Flag 'Render Body'
*/
define('XAPP_BOOTSTRAP_RENDER_BODY', 55035);
/***
* Processing Flag 'Render Body'
*/
define('XAPP_BOOTSTRAP_NEEDS_AUTHENTICATION', 55036);
/***
* Processing Flag 'Enable Google Analytics' instructs the bootstrapper to load Google Analytics
*/
define('XAPP_BOOTSTRAP_ENABLE_GOOGLE_ANALYTICS', 55037);
/***
* Logging
*/
$global_xapp_logger = null;
/***
* Processing Flag 'Setup Console'
*/
define('XAPP_LOG_PLUGIN_CREATION', 25030);
define('XAPP_LOG_XFILE_OPERATIONS', 25031);
define('XAPP_LOG_SHARED_LOGGER_PLUGINS', 25032);
define('XAPP_LOG_SHARED_LOGGER_SERVICES', 25033);
/***
* Class XApp_Bootstrap
* Utility class to do the initial work.
*/
class XApp_Bootstrap
{
/***
* Flags to use whilst the bootstrapping
*/
const FLAGS = "XAPP_BOOTSTRAP_FLAGS";
/***
* Logging flags
*/
const LOGGING_FLAGS = "XAPP_BOOTSTRAP_LOGGING_FLAGS";
/***
* The RPC server. This should be in instance to a JSON-RPC or JSONP server.
*/
const RPC_SERVER = "XAPP_BOOTSTRAP_RPC_SERVER";
/***
* The class name of the server application
*/
const SERVER_APPLICATION_CLASS = "XAPP_SERVER_APPLICATION_CLASS";
/***
* Absolute path to xapp base directory
*/
const BASEDIR = "XAPP_BOOTSTRAP_BASEDIR";
/***
* Absolute path to the xapp client directory
*/
const APPDIR = "XAPP_BOOTSTRAP_APP_DIR";
/***
* Relative path to the client app's rpc service
*/
const SERVICE = "XAPP_BOOTSTRAP_SERVICE";
/***
* Name of the client app.
*/
const APP_NAME = "XAPP_APP_NAME";
/***
* Path segment to the Dojo app.
*/
const APP_FOLDER = "XAPP_APP_FOLDER";
/***
* Relative resource variables
*/
const RELATIVE_VARIABLES = "XAPP_BOOTSTRAP_RELATIVE_VARS";
/***
* Render delegate to render out client resources into the HTML head section
*/
const RENDER_DELEGATE = "XAPP_RESOURCE_RENDER_DELEGATE";
/***
* Relative url to the client's app doc root
*/
const DOC_ROOT = "XAPP_APP_DOC_ROOT";
/***
* Additional resource config prefix
*/
const RESOURCE_CONFIG_SUFFIX = "XAPP_RESOURCE_CONFIG_SUFFIX";
/***
* Additional resource config prefix
*/
const RESOURCE_CONFIG_PREFIX = "XAPP_RESOURCE_CONFIG_PREFIX";
/***
* Additional resource renderer prefix : wordpress/joomla
*/
const RESOURCE_RENDERER_PREFIX = "XAPP_RESOURCE_RENDERER_PREFIX";
/***
* Resource renderer class
*/
const RESOURCE_RENDERER_CLZ = "XAPP_RESOURCE_RENDERER_CLZ";
/***
* Plugin directory
*/
const PLUGIN_DIRECTORY = "XAPP_RESOURCE_PLUGIN_DIR";
/***
* Plugin directory
*/
const PLUGIN_MASK = "XAPP_RESOURCE_PLUGIN_MASK";
/***
* Allow plugins
*/
const ALLOW_PLUGINS = "XAPP_BOOTSTRAP_ALLOW_PLUGINS";
/***
* Forbidden plugins, comma separated
*/
const PROHIBITED_PLUGINS = "XAPP_BOOTSTRAP_PROHIBITED_PLUGINS";
/***
* Auth delegate
*/
const AUTH_DELEGATE = "XAPP_BOOTSTRAP_AUTH_DELEGATE";
/***
* RPC target is the entry point for client calls
*/
const RPC_TARGET = "XAPP_BOOTSTRAP_RPC_TARGET";
/***
* Ignored RPC methods. If an auth delegate is given, its trying to build this list on own
*/
const IGNORED_RPC_METHODS = "XAPP_BOOTSTRAP_IGNORED_RPC_METHODS";
/***
* File service configuration
*/
const XFILE_CONF = "XAPP_BOOTSTRAP_FILE_CONF";
/***
* Service map
*/
const SERIVCE_CONF = "XAPP_BOOTSTRAP_RPC_SERVICES";
/***
* Gateway configuration
*/
const GATEWAY_CONF = "XAPP_BOOTSTRAP_GATEWAY_CONF";
/***
* XApp configuration
*/
const XAPP_CONF = "XAPP_BOOTSTRAP_XAPP_CONF";
/***
* Logging configuration
*/
const LOGGING_CONF = "XAPP_BOOTSTRAP_LOGGING_CONF";
/***
* Store configuration
*/
const STORE_CONF = "XAPP_BOOTSTRAP_STORE_CONF";
/***
* Demand signing of this service types
*/
const SIGNED_SERVICE_TYPES = "XAPP_BOOTSTRAP_SIGNED_SERVICE_TYPES";
/***
* Token to use for signed request
*/
const SIGNING_TOKEN = "XAPP_BOOTSTRAP_SIGNING_TOKEN";
/***
* Signing key
*/
const SIGNING_KEY = "XAPP_BOOTSTRAP_SIGNING_KEY";
/***
* Tracked logger instance, might be shared with plugins and other managed instances
*/
const LOGGER = "XAPP_BOOTSTRAP_LOGGER";
/***
* Tracked store service instance, might be shared with plugins and other managed instances
*/
const STORE = "XAPP_BOOTSTRAP_STORE";
/***
* Tracked gateway instance, might be shared with plugins and other managed instances
*/
const GATEWAY = "XAPP_BOOTSTRAP_GATEWAY";
/***
* Tracked gateway instance, might be shared with plugins and other managed instances
*/
const USER_CONF = "XAPP_BOOTSTRAP_USER_CONFIGURATION";
/**
* options dictionary for this class containing all data type values
*
* @var array
*/
public static $optionsDict = array
(
self::BASEDIR => XAPP_TYPE_STRING,
self::SERVER_APPLICATION_CLASS => XAPP_TYPE_STRING,
self::APPDIR => XAPP_TYPE_STRING,
self::SERVICE => XAPP_TYPE_STRING,
self::APP_NAME => XAPP_TYPE_STRING,
self::APP_FOLDER => XAPP_TYPE_STRING,
self::RELATIVE_VARIABLES => XAPP_TYPE_ARRAY,
self::DOC_ROOT => XAPP_TYPE_STRING,
self::RESOURCE_CONFIG_SUFFIX => XAPP_TYPE_STRING,
self::RESOURCE_RENDERER_PREFIX => XAPP_TYPE_STRING,
self::RESOURCE_RENDERER_CLZ => XAPP_TYPE_STRING,
self::RENDER_DELEGATE => XAPP_TYPE_OBJECT,
self::RPC_SERVER => XAPP_TYPE_OBJECT,
self::PLUGIN_DIRECTORY => XAPP_TYPE_STRING,
self::PLUGIN_MASK => XAPP_TYPE_STRING,
self::ALLOW_PLUGINS => array(XAPP_TYPE_BOOL,XAPP_TYPE_INT),
self::FLAGS => XAPP_TYPE_ARRAY,
self::PROHIBITED_PLUGINS => XAPP_TYPE_STRING,
self::AUTH_DELEGATE => XAPP_TYPE_OBJECT,
self::RPC_TARGET => XAPP_TYPE_STRING,
self::XFILE_CONF => XAPP_TYPE_ARRAY,
self::XAPP_CONF => XAPP_TYPE_ARRAY,
self::LOGGING_CONF => XAPP_TYPE_ARRAY,
self::STORE_CONF => XAPP_TYPE_ARRAY,
self::IGNORED_RPC_METHODS => XAPP_TYPE_ARRAY,
self::GATEWAY_CONF => XAPP_TYPE_ARRAY,
self::SIGNED_SERVICE_TYPES => XAPP_TYPE_ARRAY,
self::SIGNING_TOKEN => XAPP_TYPE_STRING,
self::SIGNING_KEY => XAPP_TYPE_STRING,
self::LOGGING_FLAGS => XAPP_TYPE_ARRAY,
self::LOGGER => XAPP_TYPE_OBJECT,
self::STORE => XAPP_TYPE_OBJECT,
self::GATEWAY => XAPP_TYPE_OBJECT,
self::SERIVCE_CONF => XAPP_TYPE_ARRAY,
self::USER_CONF => array(XAPP_TYPE_ARRAY, XAPP_TYPE_STRING, XAPP_TYPE_OBJECT),
self::RESOURCE_CONFIG_PREFIX => XAPP_TYPE_STRING
);
/**
* options mandatory map for this class contains all mandatory values
*
* @var array
*/
public static $optionsRule = array
(
self::BASEDIR => 1,
self::SERVER_APPLICATION_CLASS => 0,
self::APPDIR => 0,
self::SERVICE => 0,
self::APP_NAME => 1,
self::APP_FOLDER => 0,
self::RELATIVE_VARIABLES => 0,
self::DOC_ROOT => 0,
self::RENDER_DELEGATE => 0,
self::RESOURCE_CONFIG_SUFFIX => 0,
self::RESOURCE_RENDERER_PREFIX => 0,
self::RESOURCE_RENDERER_CLZ => 0,
self::PLUGIN_DIRECTORY => 0,
self::PLUGIN_MASK => 0,
self::ALLOW_PLUGINS => 0,
self::FLAGS => 0,
self::RPC_SERVER => 0,
self::PROHIBITED_PLUGINS => 0,
self::AUTH_DELEGATE => 0,
self::RPC_TARGET => 0,
self::IGNORED_RPC_METHODS => 0,
self::GATEWAY_CONF => 0,
self::LOGGING_CONF => 0,
self::SIGNED_SERVICE_TYPES => 0,
self::SIGNING_TOKEN => 0,
self::SIGNING_KEY => 0,
self::XFILE_CONF => 0,
self::XAPP_CONF => 0,
self::LOGGING_FLAGS => 0,
self::LOGGER => 0,
self::STORE_CONF => 0,
self::STORE => 0,
self::GATEWAY => 0,
self::SERIVCE_CONF => 0,
self::USER_CONF => 0,
self::RESOURCE_CONFIG_PREFIX => 0
);
/**
* contains the singleton instance for this class
*
* @var null|XApp_Commander_Bootstrap
*/
protected static $_instance = null;
/**
* options default value array containing all class option default values
*
* @var array
*/
public $options = array
(
self::BASEDIR => null,
self::SERVER_APPLICATION_CLASS => null,
self::APPDIR => null,
self::SERVICE => null,
self::APP_NAME => null,
self::APP_FOLDER => null,
self::RELATIVE_VARIABLES => null,
self::DOC_ROOT => null,
self::RENDER_DELEGATE => null,
self::RESOURCE_CONFIG_SUFFIX => '',
self::RESOURCE_RENDERER_PREFIX => 'joomla',
self::RESOURCE_RENDERER_CLZ => 'XApp_Joomla_Resource_Renderer',
self::PLUGIN_DIRECTORY => null,
self::PLUGIN_MASK => null,
self::ALLOW_PLUGINS => true,
self::FLAGS => array(),
self::RPC_SERVER => null,
self::LOGGER => null,
self::LOGGING_FLAGS => array(),
self::PROHIBITED_PLUGINS => '',
self::AUTH_DELEGATE => null,
self::RPC_TARGET => null,
self::IGNORED_RPC_METHODS => null,
self::GATEWAY_CONF => null,
self::LOGGING_CONF => null,
self::SIGNED_SERVICE_TYPES => null, //sign all RPC calls
self::SIGNING_TOKEN => null,
self::SIGNING_KEY => null,
self::XFILE_CONF => null,
self::XAPP_CONF => null,
self::STORE_CONF => null,
self::STORE => null,
self::GATEWAY => null,
self::SERIVCE_CONF => null,
self::USER_CONF => 0,
self::RESOURCE_CONFIG_PREFIX => ''
);
/***
* @var null|XApp_App_Renderer
*/
protected $appRenderer = null;
protected $resourceRenderer = null;
/**
* class constructor
* call parent constructor for class initialization
*
* @error 14601
* @param null|array|object $options expects optional options
*/
public function __construct($options = null)
{
xapp_set_options($options, $this);
}
public static function loadRPC()
{
if (!class_exists('XApp_Service_Entry_Utils')) {
require_once(XAPP_BASEDIR . '/XApp_Service_Entry_Utils.php');
}
XApp_Service_Entry_Utils::includeXAppRPC();
}
public static function loadMin()
{
if (!class_exists('XApp_Service_Entry_Utils')) {
require_once(XAPP_BASEDIR . '/XApp_Service_Entry_Utils.php');
}
XApp_Service_Entry_Utils::includeXAppCore();
/*require_once(XAPP_BASEDIR . '/connect/utils/Debugging.php');*/
require_once(XAPP_BASEDIR . '/Log/Exception/Exception.php');
require_once(XAPP_BASEDIR . '/Log/Interface/Interface.php');
require_once(XAPP_BASEDIR . '/Log/Log.php');
require_once(XAPP_BASEDIR . '/Log/Writer.php');
require_once(XAPP_BASEDIR . '/Log/Writer/File.php');
}
/***
*
*/
public static function isRPC()
{
if (!class_exists('XApp_Service_Entry_Utils')) {
include_once(XAPP_BASEDIR . 'XApp_Service_Entry_Utils.php');
}
$_REQUEST_TYPE = XApp_Service_Entry_Utils::getServiceType();
return
$_REQUEST_TYPE == XApp_Service_Entry_Utils::SMD_CALL ||
$_REQUEST_TYPE == XApp_Service_Entry_Utils::SMD_GET ||
$_REQUEST_TYPE == XApp_Service_Entry_Utils::UPLOAD ||
$_REQUEST_TYPE == XApp_Service_Entry_Utils::CBTREE ||
$_REQUEST_TYPE == XApp_Service_Entry_Utils::DOWNLOAD;
}
/***
* Return current request url
* @return string
*/
public static function getUrl()
{
$pageURL = 'http';
if (array_key_exists("HTTPS", $_SERVER) && $_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
/***
*
*/
public static function loadDebuggingTools()
{
xapp_import('xapp.Utils.Debugging');
}
public static function getConsoleType()
{
$agent = '';
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$agent = $_SERVER['HTTP_USER_AGENT'];
}
if (strlen(strstr($agent, "Firefox")) > 0) {
return 'firephp';
} elseif ((strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false)) {
return 'chromephp';
}
return false;
}
/***
*
*/
public function printPaths()
{
echo('XAPP BOOTSTRAP-PATHS' . '<br/>');
echo('BASE DIR : ' . xapp_get_option(self::BASEDIR, $this) . '<br/>');
echo('APP DIR : ' . xapp_get_option(self::APPDIR, $this) . '<br/>');
echo('SERVICE : ' . xapp_get_option(self::SERVICE, $this) . '<br/>');
echo('APP NAME : ' . xapp_get_option(self::APP_NAME, $this) . '<br/>');
echo('APP FOLDER : ' . xapp_get_option(self::APP_FOLDER, $this) . '<br/>');
echo('PLUGIN_DIR: ' . xapp_get_option(self::PLUGIN_DIRECTORY, $this) . '<br/>');
echo('PLUGIN_MAST: ' . xapp_get_option(self::PLUGIN_MASK, $this) . '<br/>');
echo('DOC ROOT : ' . xapp_get_option(self::DOC_ROOT, $this) . '<br/><br/>');
}
public function getPluginResources($plugins, $runtTimeConfiguration,$resourceConfig)
{
$result = array();
foreach ($plugins as $plugin) {
if ($plugin->resources && $plugin->resources->{$runtTimeConfiguration}) {
$result[] = $plugin->resources->{$runtTimeConfiguration}->items;
}
}
return $result;
}
public function init()
{
$flags = xapp_get_option(self::FLAGS, $this);
self::$_instance = $this;
/***
* The very basic paths
*/
if (!defined('XAPP_BASEDIR')) {
define("XAPP_BASEDIR", xapp_get_option(self::BASEDIR, $this));
}
if (!defined('XAPP_LIB')) {
define("XAPP_LIB", XAPP_BASEDIR . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR);
}
/***
* Load utils
*/
if (!class_exists('XApp_Service_Entry_Utils')) {
include_once(XAPP_BASEDIR . 'XApp_Service_Entry_Utils.php');
}
/***
* Get run-time configuration, there is 'debug' and 'release'. For both cases there are
* different resources to load.
*/
$XAPP_RUN_TIME_CONFIGURATION = XApp_Service_Entry_Utils::getRunTimeConfiguration();
/***
* Load dependencies
*/
$this->loadDependencies(xapp_get_option(self::FLAGS, $this));
//some debugging tools
XApp_Service_Entry_Utils::includeXAppDebugTools();
$plugins = null;
$pluginResources = null;
$xComPluginManager = null;
$logger = null;
$loggingFlags = xapp_has_option(self::LOGGING_FLAGS, $this) ? xapp_get_option(
self::LOGGING_FLAGS,
$this
) : array();
/***
* Setup Logger
*/
if (in_array(XAPP_BOOTSTRAP_SETUP_LOGGER, $flags) && xapp_has_option(self::LOGGING_CONF, $this)) {
$logger = $this->setupLogger(xapp_get_option(self::LOGGING_CONF));
xapp_set_option(self::LOGGER, $logger, $this);
if (!function_exists('xp_log')) {
function xp_log($message)
{
$bootstrap = XApp_Bootstrap::instance();
$log = xapp_get_option(XApp_Bootstrap::LOGGER, $bootstrap);
$log->log($message);
}
}
} else {
if (!function_exists('xp_log')) {
//fake logger
function xp_log($message)
{};
}
}
/***
* Setup XApp-PHP
*/
if (in_array(XAPP_BOOTSTRAP_SETUP_XAPP, $flags)) {
$this->setupXApp(xapp_has_option(self::XAPP_CONF, $this) ? xapp_get_option(self::XAPP_CONF, $this) : null);
}
/***
* Setup RPC Server
*/
if (in_array(XAPP_BOOTSTRAP_SETUP_RPC, $flags)) {
$this->setupRPC();
}
$storeService = null;
/***
* Setup storage
*/
if (in_array(XAPP_BOOTSTRAP_SETUP_STORE, $flags) && xapp_has_option(self::STORE_CONF, $this)) {
$storeService = $this->setupStore(xapp_get_option(self::STORE_CONF, $this));
//$this->testStore($storeService);
xapp_set_option(self::STORE, $storeService, $this);
}
/***
* Prepare resource renderer
*/
if (in_array(XAPP_BOOTSTRAP_LOAD_CLIENT_RESOURCES, $flags)) {
//clients resource config path
$XAPP_RESOURCE_CONFIG_PATH = '' . xapp_get_option(self::APPDIR, $this) . DIRECTORY_SEPARATOR;
if ($XAPP_RUN_TIME_CONFIGURATION === 'debug') {
$XAPP_RESOURCE_CONFIG_PATH .= 'lib' . DIRECTORY_SEPARATOR . xapp_get_option(
self::APP_NAME,
$this
) . DIRECTORY_SEPARATOR . 'resources-' . $XAPP_RUN_TIME_CONFIGURATION . xapp_get_option(
self::RESOURCE_CONFIG_SUFFIX,
$this
) . '.json';
} else {
if ($XAPP_RUN_TIME_CONFIGURATION === 'release') {
$XAPP_RESOURCE_CONFIG_PATH .= DIRECTORY_SEPARATOR . xapp_get_option(
self::APP_FOLDER,
$this
) . DIRECTORY_SEPARATOR . xapp_get_option(
self::APP_NAME,
$this
) . DIRECTORY_SEPARATOR . 'resources-' . $XAPP_RUN_TIME_CONFIGURATION . xapp_get_option(
self::RESOURCE_CONFIG_SUFFIX,
$this
) . '.json';
}
}
}
/***
* Load plugin resources
*/
if (in_array(XAPP_BOOTSTRAP_LOAD_PLUGIN_RESOURCES, $flags) || in_array(
XAPP_BOOTSTRAP_REGISTER_SERVER_PLUGINS,
$flags
)
) {
if (xapp_get_option(self::ALLOW_PLUGINS, $this) && xapp_get_option(
self::PLUGIN_DIRECTORY,
$this
) && xapp_get_option(self::PLUGIN_DIRECTORY, $this)
) {
if (!$xComPluginManager) {
$xComPluginManager = new XApp_Commander_PluginManager();
}
$pluginResources = $xComPluginManager->getPluginResources(
xapp_get_option(self::PLUGIN_DIRECTORY, $this),
xapp_get_option(self::PLUGIN_DIRECTORY, $this),
xapp_get_option(self::PLUGIN_MASK, $this)
);
}
}
/***
* Get plugins
*/
if (in_array(XAPP_BOOTSTRAP_REGISTER_SERVER_PLUGINS, $flags)) {
if (
xapp_get_option(self::ALLOW_PLUGINS, $this) &&
xapp_get_option(self::PLUGIN_DIRECTORY, $this) && xapp_get_option(self::PLUGIN_DIRECTORY, $this)
) {
if (!$xComPluginManager) {
$xComPluginManager = new XApp_Commander_PluginManager();
}
$plugins = $xComPluginManager->getPlugins(
xapp_get_option(self::PLUGIN_DIRECTORY, $this),
xapp_get_option(self::PLUGIN_MASK, $this)
);
} else {
}
}
$pluginInstances = array();
/***
* Register server plugins
*/
if ($xComPluginManager !== null &&
count($plugins) && //we have plugin descriptions
xapp_get_option(self::RPC_SERVER, $this) && //there must be RPC server
in_array(XAPP_BOOTSTRAP_REGISTER_SERVER_PLUGINS, $flags)
) //yes, we want plugins
{
switch (XApp_Service_Entry_Utils::getServiceType()) {
/***
* JSON-RPC-2.0 call. In this case we are only loading the plugin which has been specified in the RPC call('service')
*/
case XApp_Service_Entry_Utils::SMD_CALL: {
/***
* Load the plugin by its service class name. A RPC POST request looks like this :
* {
* "id": 0,
* "method": "Xapp_FileService.rename",
* "params": {
* "path": "./tmp/wp-mail.php",
* "newFileName": "wp-mail.php2"
* },
* "jsonrpc": "2.0"
* }
*
* In case we go over JSONP, the url looks like this :
*
* http://0.0.0.0/zoo254/components/com_xas/xapp/index.php?service=XLESS.test&id=4&callback=as
*
*/
$method = XApp_Service_Entry_Utils::getSMDMethod();
$serviceClass = null;
if ($method != null && strpos($method, '.') != -1) {
$methodSplitted = explode('.', $method);
if ($methodSplitted && count($methodSplitted) == 2) {
$serviceClass = $methodSplitted[0];
}
}
if ($serviceClass) {
if (in_array(XAPP_LOG_PLUGIN_CREATION, $loggingFlags)) {
$this->log('Calling service class::' . $serviceClass);
}
foreach ($plugins as $pluginConfig) {
//load only when not prohibited
$prohibited = explode(',', xapp_get_option(self::PROHIBITED_PLUGINS, $this));
if (!in_array($serviceClass, $prohibited)) {
if ($pluginConfig !== null && is_object($pluginConfig)) {
//pull in if not done yet
if (!class_exists($pluginConfig->name)) {
$pluginPath = xapp_get_option(
self::PLUGIN_DIRECTORY,
$this
) . DIRECTORY_SEPARATOR . $pluginConfig->location . DIRECTORY_SEPARATOR . $pluginConfig->name . '.php';
if (in_array(XAPP_LOG_PLUGIN_CREATION, $loggingFlags)) {
$this->log('loading plugin ' . $pluginConfig->name . ' at ' . $pluginPath);
}
if (file_exists($pluginPath)) {
include_once $pluginPath;
} else {
continue;
}
}
//create instance
if (class_exists($serviceClass)) {
$plugin = $xComPluginManager->createPluginInstance(
$pluginConfig->name, //class name,
true, //yes, call plugin->load()
array(), //no service configuration
array(), //no logging configuration
xapp_get_options(), //our own configuration,
$pluginConfig //the plugin info, including all client side resources
);
if ($plugin != null) {
xapp_get_option(self::RPC_SERVER)->register($plugin, array('_load'));
array_push($pluginInstances, $plugin);
//share logger
if (in_array(XAPP_LOG_SHARED_LOGGER_PLUGINS, $loggingFlags) && $logger) {
$plugin->_setLogger($logger);
}
}
}
}
}
}
}
break;
}
/***
* JSON-RPC-2.0 Service Introspection. That means we expose all plugins as Dojo SMD! You can see the full RPC class by opening http://localhost/joomla251/administrator/index.php?option=com_xappcommander&view=rpc
*/
case XApp_Service_Entry_Utils::SMD_GET: {
foreach ($plugins as $pluginConfig) {
/***
* Skip black listed plugins
*/
$prohibited = explode(',', xapp_get_option(self::PROHIBITED_PLUGINS, $this));
if (in_array($pluginConfig->name, $prohibited)) {
continue;
}
//show only if the plugins wants to be exposed!
if (property_exists($pluginConfig, 'showSMD') && $pluginConfig->showSMD == true) {
if (!class_exists($pluginConfig->name)) {
$pluginPath = xapp_get_option(
self::PLUGIN_DIRECTORY,
$this
) . DIRECTORY_SEPARATOR . $pluginConfig->location . DIRECTORY_SEPARATOR . $pluginConfig->name . '.php';
if (in_array(XAPP_LOG_PLUGIN_CREATION, $loggingFlags)) {
$this->log('loading plugin ' . $pluginConfig->name . ' at ' . $pluginPath);
}
if (file_exists($pluginPath)) {
include_once $pluginPath;
} else {
continue;
}
}
//now register as RPC class
if (class_exists($pluginConfig->name)) {
xapp_get_option(self::RPC_SERVER)->register($pluginConfig->name);
}
}
}
break;
}
}
}
$xappFileService = null;
/***
* Setup file service
*/
if (in_array(XAPP_BOOTSTRAP_SETUP_XFILE, $flags) &&
xapp_get_option(self::RPC_SERVER, $this) &&
xapp_has_option(self::XFILE_CONF, $this)
) {
$opt = xapp_get_option(self::XFILE_CONF, $this);
$xappFileService = new Xapp_FileService($opt);
$xappFileService::$rootDirectory = xapp_get_option(
Xapp_FileService::REPOSITORY_ROOT,
xapp_get_option(self::XFILE_CONF)
);
xapp_get_option(self::RPC_SERVER)->register($xappFileService);
}
if ($xappFileService !== null && count($pluginInstances)) {
foreach ($pluginInstances as $plugin) {
$plugin->xfile = $xappFileService;
}
}
/***
* Setup store service
*/
if ($storeService) {
xapp_get_option(self::RPC_SERVER)->register($storeService);
}
/***
* More services
*/
if (in_array(XAPP_BOOTSTRAP_SETUP_SERVICES, $flags) &&
xapp_has_option(self::SERIVCE_CONF, $this) &&
xapp_get_option(self::RPC_SERVER, $this)
) {
//pull in registry of xapp core framework
XApp_Service_Entry_Utils::includeXAppRegistry();
$this->registerServices(xapp_get_option(self::SERIVCE_CONF), xapp_get_option(self::RPC_SERVER));
}
/***
* Setup gateway
*/
if (in_array(XAPP_BOOTSTRAP_SETUP_GATEWAY, $flags) &&
xapp_get_option(self::RPC_SERVER, $this)
) {
try {
$needsSigning = false;
$opt = xapp_has_option(self::GATEWAY_CONF) ? xapp_get_option(self::GATEWAY_CONF) : array();
/***
* Raise security and demand that the client did sign its request
*/
$signServiceTypes = xapp_get_option(self::SIGNED_SERVICE_TYPES, $this);
if (in_array(XApp_Service_Entry_Utils::getServiceType(), $signServiceTypes)) {
$needsSigning = true;
//set signed
$opt[Xapp_Rpc_Gateway::SIGNED_REQUEST] = true;
//complete configuration
if (!array_key_exists(Xapp_Rpc_Gateway::SIGNED_REQUEST_METHOD, $opt)) {
$opt[Xapp_Rpc_Gateway::SIGNED_REQUEST_METHOD] = 'user';
}
if (!array_key_exists(Xapp_Rpc_Gateway::SIGNED_REQUEST_USER_PARAM, $opt)) {
$opt[Xapp_Rpc_Gateway::SIGNED_REQUEST_USER_PARAM] = 'user';
}
//complete configuration
}
$this->setGatewayOptionArray(Xapp_Rpc_Gateway::ALLOW_IP, $opt);
$this->setGatewayOptionArray(Xapp_Rpc_Gateway::DENY_IP, $opt);
$this->setGatewayOptionArray(Xapp_Rpc_Gateway::ALLOW_HOST, $opt);
$this->setGatewayOptionArray(Xapp_Rpc_Gateway::DENY_HOST, $opt);
/***
* Create the gateway
*/
$gateway = Xapp_Rpc_Gateway::instance(xapp_get_option(self::RPC_SERVER, $this), $opt);
/***
* Set the API key for signed requests
*/
if ($needsSigning) {
$gateway->addKey(