PEAR2_SimpleChannelServer-0.2.0 › PEAR2_SimpleChannelServer-0.2.0/php/PEAR2/Pyrus/Dependency/Validator.php
- PEAR2_SimpleChannelServer-0.2.0/
- customcommand/
- pear2.php.net/
- PEAR2_Pyrus_Developer/
- PEAR2_SimpleChannelServer/
- pear2.php.net/
- data/
- pear2.php.net/
- PEAR2_Pyrus/
- built-in-commands.xml
- channel-1.0.xsd
- customcommand-2.0.xsd
- customrole-2.0.xsd
- customtask-2.0.xsd
- default_channels/
- developercommands.xml
- package-2.0.xsd
- package-2.1.xsd
- scscommands.xml
- x509rootcerts/
- AAACertificateServices
- ABA.ECOMRootCA
- AOLTimeWarnerRootCertificationAuthority1
- AOLTimeWarnerRootCertificationAuthority2
- AddTrustClass1CARoot
- AddTrustExternalCARoot
- AddTrustPublicCARoot
- AddTrustQualifiedCARoot
- AmericaOnlineRootCertificationAuthority1
- AmericaOnlineRootCertificationAuthority2
- AutoridaddeCertificacionFirmaprofesionalCIFA62634068
- BaltimoreCyberTrustRoot
- CACertSigningAuthority
- COMODOCertificationAuthority
- CertumCA
- ChambersofCommerceRoot
- Class2PrimaryCA
- DSTACESCAX6
- DSTRootCAX1
- DSTRootCAX2
- DSTRootCAX3
- DigiCertAssuredIDRootCA
- DigiCertGlobalRootCA
- DigiCertHighAssuranceEVRootCA
- DigiNotarRootCA
- DigitalSignatureTrustCo.GlobalCA1
- DigitalSignatureTrustCo.GlobalCA3
- Entrust.netCertificationAuthority(2048)
- Entrust.netClientCertificationAuthority
- Entrust.netClientCertificationAuthority2
- Entrust.netSecureServerCertificationAuthority
- Entrust.netSecureServerCertificationAuthority2
- EntrustRootCertificationAuthority
- EquifaxSecureCA
- EquifaxSecureGlobaleBusinessCA-1
- EquifaxSecureeBusinessCA-1
- EquifaxSecureeBusinessCA2
- FreeSSLCertificationAuthority
- GPRoot2
- GTECyberTrustGlobalRoot
- GTECyberTrustRoot
- GeoTrustGlobalCA
- GeoTrustGlobalCA2
- GeoTrustPrimaryCertificationAuthority
- GeoTrustUniversalCA
- GeoTrustUniversalCA2
- GlobalChambersignRoot
- GlobalSign
- GlobalSign2
- GlobalSignExtendedValidationCA
- GlobalSignRootCA
- GoDaddyClass2CA
- GoDaddySecureCertificationAuthority
- IPSCACLASE1CertificationAuthority
- IPSCACLASE3CertificationAuthority
- IPSCACLASEA1CertificationAuthority
- IPSCACLASEA3CertificationAuthority
- IPSCAChainedCAsCertificationAuthority
- IPSCATimestampingCertificationAuthority
- IPSSERVIDORES
- NetLockExpressz(ClassC)Tanusitvanykiado
- NetLockKozjegyzoi(ClassA)Tanusitvanykiado
- NetLockMinositettKozjegyzoi(ClassQA)Tanusitvanykiado
- NetLockUzleti(ClassB)Tanusitvanykiado
- NetworkSolutionsCertificateAuthority
- QuoVadisRootCA2
- QuoVadisRootCA3
- QuoVadisRootCertificationAuthority
- RSASecurity1024v3
- RSASecurity2048v3
- SecureCertificateServices
- SecureGlobalCA
- SecureTrustCA
- SecurityCommunicationRootCA
- SoneraClass1CA
- SoneraClass2CA
- StaatderNederlandenRootCA
- StarfieldClass2CA
- StartComCertificationAuthority
- SwissSignGoldCA-G2
- SwissSignPlatinumCA-G2
- SwissSignSilverCA-G2
- SwisscomRootCA1
- TCTrustCenter,Germany,Class2CA
- TCTrustCenter,Germany,Class3CA
- TDCInternetRootCA
- TDCOCESCA
- TURKTRUST
- TURKTRUST2
- TaiwanGRCA
- ThawtePersonalBasicCA
- ThawtePersonalFreemailCA
- ThawtePersonalPremiumCA
- ThawtePremiumServerCA
- ThawteSGCCA
- ThawteServerCA
- ThawteTimestampingCA
- TrustedCertificateServices
- UTN-DATACorpSGC
- UTN-USERFirst-ClientAuthenticationandEmail
- UTN-USERFirst-Hardware
- UTN-USERFirst-NetworkApplications
- UTN-USERFirst-Object
- VeriSignClass1PublicPrimaryCertificationAuthority-G3
- VeriSignClass2PublicPrimaryCertificationAuthority-G3
- VeriSignClass3PublicPrimaryCertificationAuthority-G3
- VeriSignClass3PublicPrimaryCertificationAuthority-G5
- VeriSignClass4PublicPrimaryCertificationAuthority-G3
- VeriSignTimeStampingAuthorityCA
- Verisign-RSASecureServerCA
- VerisignClass1PublicPrimaryCertificationAuthority
- VerisignClass1PublicPrimaryCertificationAuthority-G2
- VerisignClass2PublicPrimaryCertificationAuthority
- VerisignClass2PublicPrimaryCertificationAuthority-G2
- VerisignClass3PublicPrimaryCertificationAuthority
- VerisignClass3PublicPrimaryCertificationAuthority-G2
- VerisignClass4PublicPrimaryCertificationAuthority-G2
- VisaeCommerceRoot
- WellsFargoRootCertificateAuthority
- XRampGlobalCertificationAuthority
- beTRUSTedRootCA
- beTRUSTedRootCA-BaltimoreImplementation
- beTRUSTedRootCA-EntrustImplementation
- beTRUSTedRootCA-RSAImplementation
- blah.php
- thawtePrimaryRootCA
- valicert.com
- valicert.com2
- valicert.com3
- PEAR2_Pyrus_Developer/
- PEAR2_Pyrus/
- pear2.php.net/
- doc/
- pear2.php.net/
- PEAR2_HTTP_Request/
- examples/
- examples/
- examples/
- PEAR2_SimpleChannelServer/
- examples/
- PEAR2_HTTP_Request/
- pear2.php.net/
- php/
- PEAR2/
- Autoload.php
- Exception.php
- HTTP/
- MultiErrors/
- MultiErrors.php
- Pyrus/
- AtomicFileTransaction/
- AtomicFileTransaction.php
- Channel/
- Channel.php
- ChannelFile/
- Exception.php
- Parser/
- v1/
- Mirror.php
- Servers/
- Protocols/
- Protocols.php
- Servers.php
- v1.php
- ChannelFile.php
- ChannelFileInterface.php
- ChannelInterface.php
- ChannelRegistry/
- ChannelRegistry.php
- ChannelRegistryInterface.php
- Config/
- Config.php
- DER/
- BMPString.php
- BitString.php
- Boolean.php
- Choice.php
- Constructed.php
- Enumerated.php
- Exception.php
- External.php
- GeneralizedTime.php
- IA5String.php
- Integer.php
- Null.php
- NumericString.php
- OCSPRequest.php
- ObjectIdentifier.php
- OctetString.php
- Parser.php
- PrintableString.php
- Schema.php
- SchemaChoice.php
- Sequence.php
- Set.php
- String.php
- UTCTime.php
- UTF8String.php
- UniversalString.php
- VisibleString.php
- DER.php
- Dependency/
- Developer/
- CoverageAnalyzer/
- Creator/
- PackageFile/
- Runphpt/
- DirectedGraph/
- DirectedGraph.php
- DownloadProgressListener.php
- Exception.php
- FileTransactionInterface.php
- FileTransactions.php
- Filesystem.php
- HTTPException.php
- IOException.php
- Installer/
- Installer.php
- LogInterface.php
- Logger.php
- Main.php
- OSGuess.php
- PECLBuild/
- PECLBuild.php
- Package/
- Package.php
- PackageFile/
- Exception.php
- Parser/
- ValidatorInterface.php
- v2/
- BundledPackage.php
- Compatible/
- Compatible.php
- Configureoption/
- Configureoption.php
- Dependencies/
- Dependencies.php
- Developer/
- Developer.php
- Files/
- Files.php
- License/
- License.php
- Release/
- Release.php
- SimpleProperty.php
- UsesRoleTask/
- UsesRoleTask.php
- Validator.php
- v2.php
- v2Iterator/
- PackageFile.php
- PackageFileInterface.php
- PackageInterface.php
- PluginRegistry/
- PluginRegistry.php
- REST/
- REST.php
- Registry/
- Registry.php
- RegistryInterface.php
- ScriptFrontend/
- ScriptFrontend.php
- ScriptRunner.php
- Task/
- Uninstaller/
- Uninstaller.php
- Validate/
- Validate.php
- Validator/
- XMLParser/
- XMLParser.php
- XMLWriter/
- XMLWriter.php
- SimpleChannelServer/
- PEAR2/
- script/
- test/
- pear2.php.net/
- PEAR2_HTTP_Request/
- _setup.php
- get_large_file.phpt
- headers.001.phpt
- headers.002.phpt
- headers.003.phpt
- headers.004.phpt
- http/
- phpsocket/
- phpstream/
- shared/
- testFiles/
- PEAR2_HTTP_Request/
- pear2.php.net/
- www/
- pear2.php.net/
- PEAR2_Pyrus_Developer/
- pear2.php.net/
- customcommand/
- package.xml
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
<?php
/**
* \PEAR2\Pyrus\Dependency\Validator, advanced dependency validation
*
* PHP versions 4 and 5
*
* @category PEAR2
* @package PEAR2_Pyrus
* @author Greg Beaver <cellog@php.net>
* @copyright 2010 The PEAR Group
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version SVN: $Id$
* @link http://svn.php.net/viewvc/pear2/Pyrus/
*/
/**
* Dependency check for PEAR2 packages
*
* @category PEAR2
* @package PEAR2_Pyrus
* @author Greg Beaver <cellog@php.net>
* @copyright 2010 The PEAR Group
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @link http://svn.php.net/viewvc/pear2/Pyrus/
*/
namespace PEAR2\Pyrus\Dependency;
use \PEAR2\Pyrus\Main as Main, \PEAR2\Pyrus\Config as Config, \PEAR2\Pyrus\Validate as Validate;
class Validator
{
/**
* @var \PEAR2\MultiErrors
*/
protected $errs;
/**
* One of the \PEAR2\Pyrus\Validate::* states
* @see \PEAR2\Pyrus\Validate::NORMAL
* @var integer
*/
var $_state;
/**
* @var \PEAR2\Pyrus\OSGuess
*/
var $_os;
/**
* Package to validate
* @var \PEAR2\Pyrus\Package
*/
var $_currentPackage;
/**
* @param \PEAR2\Pyrus\Package
* @param int installation state (one of \PEAR2\Pyrus\Validate::*)
* @param \PEAR2\MultiErrors
*/
function __construct($package, $state = Validate::INSTALLING, \PEAR2\MultiErrors $errs)
{
$this->_state = $state;
$this->_currentPackage = $package;
$this->errs = $errs;
}
function _getExtraString($dep)
{
$extra = ' (';
if ($dep->type != 'extension' && isset($dep->uri)) {
return '';
}
if (isset($dep->recommended)) {
$extra .= 'recommended version ' . $dep->recommended;
} else {
if (isset($dep->min)) {
$extra .= 'version >= ' . $dep->min;
}
if (isset($dep->max)) {
if ($extra != ' (') {
$extra .= ', ';
}
$extra .= 'version <= ' . $dep->max;
}
if (isset($dep->exclude)) {
if (!is_array($dep->exclude)) {
$dep->exclude = array($dep->exclude);
}
if ($extra != ' (') {
$extra .= ', ';
}
$extra .= 'excluded versions: ';
foreach ($dep->exclude as $i => $exclude) {
if ($i) {
$extra .= ', ';
}
$extra .= $exclude;
}
}
}
$extra .= ')';
if ($extra == ' ()') {
$extra = '';
}
return $extra;
}
/**
* This makes unit-testing a heck of a lot easier
*/
function getPHP_OS()
{
return PHP_OS;
}
/**
* This makes unit-testing a heck of a lot easier
*/
function getsysname()
{
$this->_os = new \PEAR2\Pyrus\OSGuess;
return $this->_os->getSysname();
}
/**
* Specify a dependency on an OS. Use arch for detailed os/processor information
*
* There are two generic OS dependencies that will be the most common, unix and windows.
* Other options are linux, freebsd, darwin (OS X), sunos, irix, hpux, aix
*/
function validateOsDependency(\PEAR2\Pyrus\PackageFile\v2\Dependencies\Dep $dep)
{
if ($this->_state != Validate::INSTALLING && $this->_state != Validate::DOWNLOADING) {
return true;
}
if ($dep->name == '*') {
return true; // no one will do conflicts with *, so assume no conflicts
}
switch (strtolower($dep->name)) {
case 'windows' :
if ($dep->conflicts) {
if (strtolower(substr($this->getPHP_OS(), 0, 3)) == 'win') {
$msg = "Cannot install %s on Windows";
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning("warning: " . $msg);
}
} else {
if (strtolower(substr($this->getPHP_OS(), 0, 3)) != 'win') {
$msg = "Can only install %s on Windows";
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning("warning: " . $msg);
}
}
break;
case 'unix' :
$unices = array('linux', 'freebsd', 'darwin', 'sunos', 'irix', 'hpux', 'aix');
if ($dep->conflicts) {
if (in_array(strtolower($this->getSysname()), $unices)) {
$msg = "Cannot install %s on any Unix system";
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning("warning: " . $msg);
}
} else {
if (!in_array(strtolower($this->getSysname()), $unices)) {
$msg = "Can only install %s on a Unix system";
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning("warning: " . $msg);
}
}
break;
default :
if ($dep->conflicts) {
if (strtolower($dep->name) == strtolower($this->getSysname())) {
$msg = 'Cannot install %s on ' . $dep->name . ' operating system';
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
} else {
if (strtolower($dep->name) != strtolower($this->getSysname())) {
$msg = 'Cannot install %s on ' . $this->getSysname() .
' operating system, can only install on ' . $dep->name;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
}
}
return true;
}
/**
* This makes unit-testing a heck of a lot easier
*/
function matchSignature($pattern)
{
$this->_os = new \PEAR2\Pyrus\OSGuess;
return $this->_os->matchSignature($pattern);
}
/**
* Specify a complex dependency on an OS/processor/kernel version,
* Use OS for simple operating system dependency.
*
* This is the only dependency that accepts an eregable pattern. The pattern
* will be matched against the php_uname() output parsed by OS_Guess
*/
function validateArchDependency($dep)
{
if ($this->_state != Validate::INSTALLING) {
return true;
}
if ($this->matchSignature($dep->pattern)) {
if ($dep->conflicts) {
$msg = '%s Architecture dependency failed, cannot match "' . $dep->pattern . '"';
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
return true;
}
if ($dep->conflicts) {
return true;
}
$msg = '%s Architecture dependency failed, does not match "' . $dep->pattern . '"';
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
/**
* This makes unit-testing a heck of a lot easier
*/
function extension_loaded($name)
{
return extension_loaded($name);
}
/**
* This makes unit-testing a heck of a lot easier
*/
function phpversion($name = null)
{
if ($name !== null) {
return phpversion($name);
}
return phpversion();
}
function validateExtensionDependency(\PEAR2\Pyrus\PackageFile\v2\Dependencies\Package $dep)
{
if ($this->_state != Validate::INSTALLING && $this->_state != Validate::DOWNLOADING) {
return true;
}
$required = $dep->deptype == 'required';
$loaded = $this->extension_loaded($dep->name);
$extra = $this->_getExtraString($dep);
if (!isset($dep->min) && !isset($dep->max) &&
!isset($dep->recommended) && !isset($dep->exclude)
) {
if ($loaded) {
if ($dep->conflicts) {
$msg = '%s conflicts with PHP extension "' . $dep->name . '"' . $extra;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
return true;
}
if ($dep->conflicts) {
return true;
}
if ($required) {
$msg = '%s requires PHP extension "' . $dep->name . '"' . $extra;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
return $this->warning('%s can optionally use PHP extension "' .
$dep->name . '"' . $extra);
}
if (!$loaded) {
if ($dep->conflicts) {
return true;
}
if (!$required) {
return $this->warning('%s can optionally use PHP extension "' .
$dep->name . '"' . $extra);
}
$msg = '%s requires PHP extension "' . $dep->name . '"' . $extra;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
$version = (string) $this->phpversion($dep->name);
if (empty($version)) {
$version = '0';
}
$fail = false;
if (isset($dep->min)) {
if (!version_compare($version, $dep->min, '>=')) {
$fail = true;
}
}
if (isset($dep->max)) {
if (!version_compare($version, $dep->max, '<=')) {
$fail = true;
}
}
if ($fail && !$dep->conflicts) {
$msg = '%s requires PHP extension "' . $dep->name . '"' . $extra .
', installed version is ' . $version;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
} elseif (!isset($dep->exclude) && (isset($dep->min) || isset($dep->max)) && !$fail && $dep->conflicts) {
$msg = '%s conflicts with PHP extension "' . $dep->name . '"' . $extra .
', installed version is ' . $version;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
if (isset($dep->exclude)) {
// exclude ordinarily tells the installer "install anything but these versions"
// when paired with conflicts, it becomes "install only these versions"
$conflicts = $dep->conflicts;
foreach ($dep->exclude as $exclude) {
if (version_compare($version, $exclude, '==')) {
if ($conflicts) {
$fail = false;
break;
}
$fail = true;
break;
} else {
if ($conflicts) {
$fail = true;
}
}
}
}
if ($fail) {
conflict_error:
$msg = '%s is not compatible with version ' . $version . ' of PHP extension "' .
$dep->name . '", installed version is ' . $version;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
if (isset($dep->recommended)) {
if (version_compare($version, $dep->recommended, '==')) {
return true;
}
$msg = '%s dependency: PHP extension ' . $dep->name .
' version "' . $version . '"' .
' is not the recommended version "' . $dep->recommended . '"';
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg . ', but may be compatible, use --force to install');
}
return $this->warning('warning: ' . $msg);
}
return true;
}
function validatePhpDependency(\PEAR2\Pyrus\PackageFile\v2\Dependencies\Dep $dep)
{
if ($this->_state != Validate::INSTALLING && $this->_state != Validate::DOWNLOADING) {
return true;
}
$version = $this->phpversion();
$extra = $this->_getExtraString($dep);
if (isset($dep->min)) {
if (!version_compare($version, $dep->min, '>=')) {
$msg = '%s requires PHP' . $extra . ', installed version is ' . $version;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
}
if (isset($dep->max)) {
if (!version_compare($version, $dep->max, '<=')) {
$msg ='%s requires PHP' . $extra . ', installed version is ' . $version;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
}
if (isset($dep->exclude)) {
foreach ($dep->exclude as $exclude) {
if (version_compare($version, $exclude, '==')) {
$msg = '%s is not compatible with PHP version ' . $exclude;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
}
}
return true;
}
/**
* This makes unit-testing a heck of a lot easier
*/
function getPEARVersion()
{
return '@PACKAGE_VERSION@' === '@'.'PACKAGE_VERSION@' ? '2.0.0' : '@PACKAGE_VERSION@';
}
function validatePearinstallerDependency(\PEAR2\Pyrus\PackageFile\v2\Dependencies\Dep $dep)
{
$pearversion = $this->getPEARVersion();
$extra = $this->_getExtraString($dep);
if (version_compare($pearversion, $dep->min, '<')) {
$msg = '%s requires PEAR Installer' . $extra . ', installed version is ' . $pearversion;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
if (isset($dep->max)) {
if (version_compare($pearversion, $dep->max, '>')) {
$msg = '%s requires PEAR Installer' . $extra . ', installed version is ' . $pearversion;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
}
if (isset($dep->exclude)) {
foreach ($dep->exclude as $exclude) {
if (version_compare($exclude, $pearversion, '==')) {
$msg = '%s is not compatible with PEAR Installer version ' . $exclude;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
}
}
return true;
}
function validateSubpackageDependency(\PEAR2\Pyrus\PackageFile\v2\Dependencies\Package $dep, $params)
{
return $this->validatePackageDependency($dep, $params);
}
/**
* @param array dependency information (2.0 format)
* @param boolean whether this is a required dependency
* @param array a list of downloaded packages to be installed, if any
*/
function validatePackageDependency(\PEAR2\Pyrus\PackageFile\v2\Dependencies\Package $dep, $params)
{
if ($this->_state != Validate::INSTALLING && $this->_state != Validate::DOWNLOADING) {
return true;
}
$required = $dep->deptype == 'required';
if (isset($dep->providesextension)) {
if ($this->extension_loaded($dep->providesextension)) {
$req = $required ? 'required' : 'optional';
$info = $dep->getInfo();
$info['name'] = $info['providesextension'];
$subdep = new \PEAR2\Pyrus\PackageFile\v2\Dependencies\Package(
$req, 'extension', null, $info, 0);
$ret = $this->validateExtensionDependency($subdep);
if ($ret === true) {
return true;
}
}
}
if ($this->_state == Validate::INSTALLING) {
return $this->_validatePackageInstall($dep);
}
if ($this->_state == Validate::DOWNLOADING) {
return $this->_validatePackageDownload($dep, $params);
}
}
function _validatePackageDownload(\PEAR2\Pyrus\PackageFile\v2\Dependencies\Package $dep, $params)
{
$required = $dep->deptype === 'required';
$depname = Config::parsedPackageNameToString(array('package' => $dep->name,
'channel' => $dep->channel), true);
$found = false;
foreach ($params as $param) {
if ($param->name == $dep->name && $param->channel == $dep->channel) {
$found = true;
break;
}
}
if ($found) {
$version = $param->version['release'];
$installed = false;
$downloaded = true;
} else {
if (Config::current()->registry->exists($dep->name, $dep->channel)) {
$installed = true;
$downloaded = false;
$version = Config::current()->registry->info($dep->name,
$dep->channel, 'version');
} else {
$version = 'not installed or downloaded';
$installed = false;
$downloaded = false;
}
}
$extra = $this->_getExtraString($dep);
if (!isset($dep->min) && !isset($dep->max) &&
!isset($dep->recommended) && !isset($dep->exclude)) {
if ($installed || $downloaded) {
$installed = $installed ? 'installed' : 'downloaded';
if ($dep->conflicts) {
$rest = ", $installed version is " . $version;
$msg = '%s conflicts with package "' . $depname . '"' . $extra . $rest;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
return true;
}
if ($dep->conflicts) {
return true;
}
if ($required) {
$msg = '%s requires package "' . $depname . '"' . $extra;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
return $this->warning('%s can optionally use package "' . $depname . '"' . $extra);
}
if (!$installed && !$downloaded) {
if ($dep->conflicts) {
return true;
}
if ($required) {
$msg = '%s requires package "' . $depname . '"' . $extra;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
return $this->warning('%s can optionally use package "' . $depname . '"' . $extra);
}
$fail = false;
if (isset($dep->min)) {
if (version_compare($version, $dep->min, '<')) {
$fail = true;
}
}
if (isset($dep->max)) {
if (version_compare($version, $dep->max, '>')) {
$fail = true;
}
}
if ($fail && !$dep->conflicts) {
$installed = $installed ? 'installed' : 'downloaded';
$dep = Config::parsedPackageNameToString(array('package' => $dep->name,
'channel' => $dep->channel), true);
$msg = '%s requires package "' . $depname . '"' . $extra . ", $installed version is " . $version;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
} elseif (!isset($dep->exclude) && (isset($dep->min) || isset($dep->max)) && !$fail && $dep->conflicts) {
$installed = $installed ? 'installed' : 'downloaded';
$msg = '%s conflicts with package "' . $depname . '"' . $extra . ', ' .
$installed . ' version is ' . $version;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
if (isset($dep->exclude)) {
// exclude ordinarily tells the installer "install anything but these versions"
// when paired with conflicts, it becomes "install only these versions"
$conflicts = $dep->conflicts;
foreach ($dep->exclude as $exclude) {
if (version_compare($version, $exclude, '==')) {
if ($conflicts) {
$fail = false;
break;
}
$fail = true;
break;
} else {
if ($conflicts) {
$fail = true;
}
}
}
} elseif ($dep->conflicts) {
return true;
}
if ($fail) {
$installed = $installed ? 'installed' : 'downloaded';
$msg = '%s is not compatible with version ' . $version . ' of package "' .
$depname . '", ' . $installed . ' version is ' . $version;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
if (isset($dep->recommended)) {
if (version_compare($version, $dep->recommended, '==')) {
return true;
}
if (!$found && $installed) {
$param = Config::current()->registry->package[$dep->channel . '/' . $dep->name];
}
if ($param) {
$found = false;
foreach ($params as $parent) {
if ($parent->name == $this->_currentPackage['package'] &&
$parent->channel == $this->_currentPackage['channel']) {
$found = true;
break;
}
}
if ($found) {
if ($param->isCompatible($parent)) {
return true;
}
}
}
$installed = $installed ? 'installed' : 'downloaded';
$msg = '%s dependency package "' . $depname . '" ' . $installed . ' version ' .
$version . ' is not the recommended version ' . $dep->recommended;
if (
!isset(Main::$options['nodeps']) &&
!isset(Main::$options['force']) &&
!isset(Main::$options['loose'])
) {
return $this->raiseError($msg . ', but may be compatible, use --force to install');
}
return $this->warning('warning: ' . $msg);
}
return true;
}
function _validatePackageInstall($dep)
{
return $this->_validatePackageDownload($dep, array());
}
function validatePackageUninstall($dep, $param)
{
if ($dep->conflicts) {
return true; // uninstall OK - these packages conflict (probably installed with --force)
}
$required = $dep->deptype == 'required';
$depname = Config::parsedPackageNameToString(array('package' => $dep->name,
'channel' => $dep->channel), true);
$extra = $this->_getExtraString($dep);
if (!isset($dep->min) && !isset($dep->max) && !isset($dep->exclude)) {
if ($required) {
$msg = '"' . $depname . '" is required by installed package %s' . $extra;
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
return $this->warning('"' . $depname . '" can be optionally used by ' .
'installed package %s' . $extra);
}
$version = $param->version['release'];
$fail = false;
if (isset($dep->max) && version_compare($version, $dep->max, '<=')) {
$fail = true;
}
if (isset($dep->min)) {
if (version_compare($version, $dep->min, '>=')) {
$fail = true;
} else {
$fail = false;
}
}
if (isset($dep->exclude)) {
$fail = true;
foreach ($dep->exclude as $exclude) {
if (version_compare($version, $exclude, '==')) {
// rare case - we conflict with the installed package,
// so uninstalling is just fine
$fail = false;
break;
}
}
}
if ($fail) {
if ($required) {
$msg = $depname . $extra . ' is required by installed package "%s"';
if (!isset(Main::$options['nodeps']) && !isset(Main::$options['force'])) {
return $this->raiseError($msg);
}
return $this->warning('warning: ' . $msg);
}
return $this->warning($depname . $extra . ' can be optionally used by installed package' .
' "%s"');
}
return true;
}
/**
* validate a downloaded package against installed packages
*
* @param $pkg downloaded package package.xml object
* @param array $params full list of packages to install
* @return bool
*/
function validateDownloadedPackage(\PEAR2\Pyrus\PackageFileInterface $pkg, $params = array())
{
$me = $pkg->channel . '/' . $pkg->name;
$reg = Config::current()->registry;
$deppackages = $reg->getDependentPackages($pkg);
$fail = false;
if ($deppackages) {
$actual = array();
// first, remove packages that will be installed
foreach ($deppackages as $package) {
foreach ($params as $packd) {
if (strtolower($packd->name) == strtolower($package->name) &&
$packd->channel == $package->channel) {
\PEAR2\Pyrus\Logger::log(3, 'skipping installed package check of "' .
Config::parsedPackageNameToString(
array('channel' => $package->channel, 'package' => $package->name),
true) .
'", version "' . $packd->version['release'] . '" will be ' .
'downloaded and installed');
continue 2;
}
}
$actual[] = $package;
}
foreach ($actual as $package) {
$checker = new \PEAR2\Pyrus\Dependency\Validator(
array('channel' => $package->channel, 'package' => $package->name),
$this->_state, $this->errs);
foreach ($params as $packd) {
$deps = $package->dependencies['required']->package;
if (isset($deps[$me])) {
$ret = $checker->_validatePackageDownload($deps[$me], array($pkg, $package));
}
$deps = $package->dependencies['required']->subpackage;
if (isset($deps[$me])) {
$ret = $checker->_validatePackageDownload($deps[$me], array($pkg));
}
$deps = $package->dependencies['optional']->package;
if (isset($deps[$me])) {
$ret = $checker->_validatePackageDownload($deps[$me], array($pkg, $package));
}
$deps = $package->dependencies['optional']->subpackage;
if (isset($deps[$me])) {
$ret = $checker->_validatePackageDownload($deps[$me], array($pkg));
}
}
}
}
if (count($this->errs->E_ERROR)) {
return $this->raiseError(
'%s cannot be installed, conflicts with installed packages');
}
return true;
}
function raiseError($msg)
{
if (isset(Main::$options['ignore-errors'])) {
return $this->warning($msg);
}
$package = Config::parsedPackageNameToString($this->_currentPackage, true);
$this->errs->E_ERROR[] = new Exception(sprintf($msg, $package));
return false;
}
function warning($msg)
{
$package = Config::parsedPackageNameToString($this->_currentPackage, true);
$this->errs->E_WARNING[] = new Exception(sprintf($msg, $package));
return true;
}
}EOF
