Bearsampp 2026.9.23
Loading...
Searching...
No Matches
v1.php
Go to the documentation of this file.
1<?php
18require_once 'PEAR/ErrorStack.php';
19
23define('PEAR_PACKAGEFILE_ERROR_NO_XML_EXT', 3);
24
28define('PEAR_PACKAGEFILE_ERROR_CANT_MAKE_PARSER', 4);
29
33define('PEAR_PACKAGEFILE_ERROR_PARSER_ERROR', 5);
34
38define('PEAR_PACKAGEFILE_ERROR_NO_NAME', 6);
39
43define('PEAR_PACKAGEFILE_ERROR_INVALID_NAME', 7);
44
48define('PEAR_PACKAGEFILE_ERROR_NO_SUMMARY', 8);
49
53define('PEAR_PACKAGEFILE_ERROR_MULTILINE_SUMMARY', 9);
54
58define('PEAR_PACKAGEFILE_ERROR_NO_DESCRIPTION', 10);
59
63define('PEAR_PACKAGEFILE_ERROR_NO_LICENSE', 11);
64
68define('PEAR_PACKAGEFILE_ERROR_NO_VERSION', 12);
69
73define('PEAR_PACKAGEFILE_ERROR_INVALID_VERSION', 13);
74
78define('PEAR_PACKAGEFILE_ERROR_NO_STATE', 14);
79
83define('PEAR_PACKAGEFILE_ERROR_INVALID_STATE', 15);
84
88define('PEAR_PACKAGEFILE_ERROR_NO_DATE', 16);
89
93define('PEAR_PACKAGEFILE_ERROR_INVALID_DATE', 17);
94
98define('PEAR_PACKAGEFILE_ERROR_NO_NOTES', 18);
99
103define('PEAR_PACKAGEFILE_ERROR_NO_MAINTAINERS', 19);
104
108define('PEAR_PACKAGEFILE_ERROR_NO_MAINTHANDLE', 20);
109
113define('PEAR_PACKAGEFILE_ERROR_NO_MAINTROLE', 21);
114
118define('PEAR_PACKAGEFILE_ERROR_NO_MAINTNAME', 22);
119
123define('PEAR_PACKAGEFILE_ERROR_NO_MAINTEMAIL', 23);
124
128define('PEAR_PACKAGEFILE_ERROR_INVALID_MAINTROLE', 24);
129
133define('PEAR_PACKAGEFILE_ERROR_NO_DEPNAME', 25);
134
138define('PEAR_PACKAGEFILE_ERROR_NO_DEPTYPE', 26);
139
143define('PEAR_PACKAGEFILE_ERROR_NO_DEPREL', 27);
144
148define('PEAR_PACKAGEFILE_ERROR_NO_DEPVERSION', 28);
149
153define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPREL', 29);
154
158define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPTYPE', 30);
159
163define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPOPTIONAL', 31);
164
168define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPNAME', 32);
169
173define('PEAR_PACKAGEFILE_ERROR_UNKNOWN_DEPCHANNEL', 33);
174
178define('PEAR_PACKAGEFILE_ERROR_DEPVERSION_IGNORED', 34);
179
183define('PEAR_PACKAGEFILE_ERROR_DEPNAME_IGNORED', 35);
184
188define('PEAR_PACKAGEFILE_ERROR_NO_CONFNAME', 36);
189
193define('PEAR_PACKAGEFILE_ERROR_NO_CONFPROMPT', 37);
194
198define('PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE', 38);
199
203define('PEAR_PACKAGEFILE_ERROR_NO_FILEROLE', 39);
204
208define('PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE', 40);
209
214define('PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX', 41);
215
219define('PEAR_PACKAGEFILE_ERROR_UNKNOWN_CHANNEL', 42);
220
224define('PEAR_PACKAGEFILE_ERROR_NO_FILES', 43);
225
229define('PEAR_PACKAGEFILE_ERROR_INVALID_FILE', 44);
230
234define('PEAR_PACKAGEFILE_ERROR_CHANNELVAL', 45);
235
239define('PEAR_PACKAGEFILE_ERROR_PHP5', 46);
240
244define('PEAR_PACKAGEFILE_ERROR_FILE_NOTFOUND', 47);
245
249define('PEAR_PACKAGEFILE_PHP_NO_NOT', 48);
250
254define('PEAR_PACKAGEFILE_ERROR_NON_ISO_CHARS', 49);
255
259define('PEAR_PACKAGEFILE_ERROR_NO_DEPPHPVERSION', 50);
260
264define('PEAR_PACKAGEFILE_ERROR_NO_LEAD', 51);
265
269define('PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME', 52);
282{
289
296
303
310
317
324
329 var $_isValid = 0;
330
342 var $_incomplete = true;
343
348 function __construct()
349 {
350 $this->_stack = new PEAR_ErrorStack('PEAR_PackageFile_v1');
351 $this->_stack->setErrorMessageTemplate($this->_getErrorMessage());
352 $this->_isValid = 0;
353 }
354
355 function installBinary($installer)
356 {
357 return false;
358 }
359
360 function isExtension($name)
361 {
362 return false;
363 }
364
366 {
367 $this->_config = &$config;
368 $this->_registry = &$config->getRegistry();
369 }
370
372 {
373 // placeholder
374 }
375
382 function setLastInstalledVersion($version)
383 {
384 $this->_packageInfo['_lastversion'] = $version;
385 }
386
391 {
392 if (isset($this->_packageInfo['_lastversion'])) {
393 return $this->_packageInfo['_lastversion'];
394 }
395 return false;
396 }
397
399 {
400 return false;
401 }
402
404 {
405 return false;
406 }
407
409 {
410 return false;
411 }
412
413 function setLogger(&$logger)
414 {
415 if ($logger && (!is_object($logger) || !method_exists($logger, 'log'))) {
416 return PEAR::raiseError('Logger must be compatible with PEAR_Common::log');
417 }
418 $this->_logger = &$logger;
419 }
420
421 function setPackagefile($file, $archive = false)
422 {
423 $this->_packageFile = $file;
424 $this->_archiveFile = $archive ? $archive : $file;
425 }
426
427 function getPackageFile()
428 {
429 return isset($this->_packageFile) ? $this->_packageFile : false;
430 }
431
432 function getPackageType()
433 {
434 return 'php';
435 }
436
437 function getArchiveFile()
438 {
439 return $this->_archiveFile;
440 }
441
442 function packageInfo($field)
443 {
444 if (!is_string($field) || empty($field) ||
445 !isset($this->_packageInfo[$field])) {
446 return false;
447 }
448 return $this->_packageInfo[$field];
449 }
450
451 function setDirtree($path)
452 {
453 if (!isset($this->_packageInfo['dirtree'])) {
454 $this->_packageInfo['dirtree'] = array();
455 }
456 $this->_packageInfo['dirtree'][$path] = true;
457 }
458
459 function getDirtree()
460 {
461 if (isset($this->_packageInfo['dirtree']) && count($this->_packageInfo['dirtree'])) {
462 return $this->_packageInfo['dirtree'];
463 }
464 return false;
465 }
466
467 function resetDirtree()
468 {
469 unset($this->_packageInfo['dirtree']);
470 }
471
472 function fromArray($pinfo)
473 {
474 $this->_incomplete = false;
475 $this->_packageInfo = $pinfo;
476 }
477
478 function isIncomplete()
479 {
480 return $this->_incomplete;
481 }
482
483 function getChannel()
484 {
485 return 'pear.php.net';
486 }
487
488 function getUri()
489 {
490 return false;
491 }
492
493 function getTime()
494 {
495 return false;
496 }
497
498 function getExtends()
499 {
500 if (isset($this->_packageInfo['extends'])) {
501 return $this->_packageInfo['extends'];
502 }
503 return false;
504 }
505
509 function toArray()
510 {
511 if (!$this->validate(PEAR_VALIDATE_NORMAL)) {
512 return false;
513 }
514 return $this->getArray();
515 }
516
517 function getArray()
518 {
519 return $this->_packageInfo;
520 }
521
522 function getName()
523 {
524 return $this->getPackage();
525 }
526
527 function getPackage()
528 {
529 if (isset($this->_packageInfo['package'])) {
530 return $this->_packageInfo['package'];
531 }
532 return false;
533 }
534
538 function setRawPackage($package)
539 {
540 $this->_packageInfo['package'] = $package;
541 }
542
543 function setPackage($package)
544 {
545 $this->_packageInfo['package'] = $package;
546 $this->_isValid = false;
547 }
548
549 function getVersion()
550 {
551 if (isset($this->_packageInfo['version'])) {
552 return $this->_packageInfo['version'];
553 }
554 return false;
555 }
556
557 function setVersion($version)
558 {
559 $this->_packageInfo['version'] = $version;
560 $this->_isValid = false;
561 }
562
564 {
565 unset($this->_packageInfo['maintainers']);
566 }
567
568 function getMaintainers()
569 {
570 if (isset($this->_packageInfo['maintainers'])) {
571 return $this->_packageInfo['maintainers'];
572 }
573 return false;
574 }
575
580 function addMaintainer($role, $handle, $name, $email)
581 {
582 $this->_packageInfo['maintainers'][] =
583 array('handle' => $handle, 'role' => $role, 'email' => $email, 'name' => $name);
584 $this->_isValid = false;
585 }
586
587 function updateMaintainer($role, $handle, $name, $email)
588 {
589 $found = false;
590 if (!isset($this->_packageInfo['maintainers']) ||
591 !is_array($this->_packageInfo['maintainers'])) {
592 return $this->addMaintainer($role, $handle, $name, $email);
593 }
594 foreach ($this->_packageInfo['maintainers'] as $i => $maintainer) {
595 if ($maintainer['handle'] == $handle) {
596 $found = $i;
597 break;
598 }
599 }
600 if ($found !== false) {
601 unset($this->_packageInfo['maintainers'][$found]);
602 $this->_packageInfo['maintainers'] =
603 array_values($this->_packageInfo['maintainers']);
604 }
605 $this->addMaintainer($role, $handle, $name, $email);
606 }
607
608 function deleteMaintainer($handle)
609 {
610 $found = false;
611 foreach ($this->_packageInfo['maintainers'] as $i => $maintainer) {
612 if ($maintainer['handle'] == $handle) {
613 $found = $i;
614 break;
615 }
616 }
617 if ($found !== false) {
618 unset($this->_packageInfo['maintainers'][$found]);
619 $this->_packageInfo['maintainers'] =
620 array_values($this->_packageInfo['maintainers']);
621 return true;
622 }
623 return false;
624 }
625
626 function getState()
627 {
628 if (isset($this->_packageInfo['release_state'])) {
629 return $this->_packageInfo['release_state'];
630 }
631 return false;
632 }
633
634 function setRawState($state)
635 {
636 $this->_packageInfo['release_state'] = $state;
637 }
638
639 function setState($state)
640 {
641 $this->_packageInfo['release_state'] = $state;
642 $this->_isValid = false;
643 }
644
645 function getDate()
646 {
647 if (isset($this->_packageInfo['release_date'])) {
648 return $this->_packageInfo['release_date'];
649 }
650 return false;
651 }
652
653 function setDate($date)
654 {
655 $this->_packageInfo['release_date'] = $date;
656 $this->_isValid = false;
657 }
658
659 function getLicense()
660 {
661 if (isset($this->_packageInfo['release_license'])) {
662 return $this->_packageInfo['release_license'];
663 }
664 return false;
665 }
666
667 function setLicense($date)
668 {
669 $this->_packageInfo['release_license'] = $date;
670 $this->_isValid = false;
671 }
672
673 function getSummary()
674 {
675 if (isset($this->_packageInfo['summary'])) {
676 return $this->_packageInfo['summary'];
677 }
678 return false;
679 }
680
681 function setSummary($summary)
682 {
683 $this->_packageInfo['summary'] = $summary;
684 $this->_isValid = false;
685 }
686
687 function getDescription()
688 {
689 if (isset($this->_packageInfo['description'])) {
690 return $this->_packageInfo['description'];
691 }
692 return false;
693 }
694
695 function setDescription($desc)
696 {
697 $this->_packageInfo['description'] = $desc;
698 $this->_isValid = false;
699 }
700
701 function getNotes()
702 {
703 if (isset($this->_packageInfo['release_notes'])) {
704 return $this->_packageInfo['release_notes'];
705 }
706 return false;
707 }
708
709 function setNotes($notes)
710 {
711 $this->_packageInfo['release_notes'] = $notes;
712 $this->_isValid = false;
713 }
714
715 function getDeps()
716 {
717 if (isset($this->_packageInfo['release_deps'])) {
718 return $this->_packageInfo['release_deps'];
719 }
720 return false;
721 }
722
726 function clearDeps()
727 {
728 unset($this->_packageInfo['release_deps']);
729 }
730
731 function addPhpDep($version, $rel)
732 {
733 $this->_isValid = false;
734 $this->_packageInfo['release_deps'][] =
735 array('type' => 'php',
736 'rel' => $rel,
737 'version' => $version);
738 }
739
740 function addPackageDep($name, $version, $rel, $optional = 'no')
741 {
742 $this->_isValid = false;
743 $dep =
744 array('type' => 'pkg',
745 'name' => $name,
746 'rel' => $rel,
747 'optional' => $optional);
748 if ($rel != 'has' && $rel != 'not') {
749 $dep['version'] = $version;
750 }
751 $this->_packageInfo['release_deps'][] = $dep;
752 }
753
754 function addExtensionDep($name, $version, $rel, $optional = 'no')
755 {
756 $this->_isValid = false;
757 $this->_packageInfo['release_deps'][] =
758 array('type' => 'ext',
759 'name' => $name,
760 'rel' => $rel,
761 'version' => $version,
762 'optional' => $optional);
763 }
764
768 function setDeps($deps)
769 {
770 $this->_packageInfo['release_deps'] = $deps;
771 }
772
773 function hasDeps()
774 {
775 return isset($this->_packageInfo['release_deps']) &&
776 count($this->_packageInfo['release_deps']);
777 }
778
779 function getDependencyGroup($group)
780 {
781 return false;
782 }
783
784 function isCompatible($pf)
785 {
786 return false;
787 }
788
789 function isSubpackageOf($p)
790 {
791 return $p->isSubpackage($this);
792 }
793
794 function isSubpackage($p)
795 {
796 return false;
797 }
798
799 function dependsOn($package, $channel)
800 {
801 if (strtolower($channel) != 'pear.php.net') {
802 return false;
803 }
804 if (!($deps = $this->getDeps())) {
805 return false;
806 }
807 foreach ($deps as $dep) {
808 if ($dep['type'] != 'pkg') {
809 continue;
810 }
811 if (strtolower($dep['name']) == strtolower($package)) {
812 return true;
813 }
814 }
815 return false;
816 }
817
819 {
820 if (isset($this->_packageInfo['configure_options'])) {
821 return $this->_packageInfo['configure_options'];
822 }
823 return false;
824 }
825
827 {
828 return isset($this->_packageInfo['configure_options']) &&
829 count($this->_packageInfo['configure_options']);
830 }
831
832 function addConfigureOption($name, $prompt, $default = false)
833 {
834 $o = array('name' => $name, 'prompt' => $prompt);
835 if ($default !== false) {
836 $o['default'] = $default;
837 }
838 if (!isset($this->_packageInfo['configure_options'])) {
839 $this->_packageInfo['configure_options'] = array();
840 }
841 $this->_packageInfo['configure_options'][] = $o;
842 }
843
845 {
846 unset($this->_packageInfo['configure_options']);
847 }
848
849 function getProvides()
850 {
851 if (isset($this->_packageInfo['provides'])) {
852 return $this->_packageInfo['provides'];
853 }
854 return false;
855 }
856
858 {
859 return false;
860 }
861
862 function addFile($dir, $file, $attrs)
863 {
864 $dir = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'), $dir);
865 if ($dir == '/' || $dir == '') {
866 $dir = '';
867 } else {
868 $dir .= '/';
869 }
870 $file = $dir . $file;
871 $file = preg_replace('![\\/]+!', '/', $file);
872 $this->_packageInfo['filelist'][$file] = $attrs;
873 }
874
876 {
877 return $this->getFilelist();
878 }
879
880 function getFilelist()
881 {
882 if (isset($this->_packageInfo['filelist'])) {
883 return $this->_packageInfo['filelist'];
884 }
885 return false;
886 }
887
888 function setFileAttribute($file, $attr, $value)
889 {
890 $this->_packageInfo['filelist'][$file][$attr] = $value;
891 }
892
893 function resetFilelist()
894 {
895 $this->_packageInfo['filelist'] = array();
896 }
897
898 function setInstalledAs($file, $path)
899 {
900 if ($path) {
901 return $this->_packageInfo['filelist'][$file]['installed_as'] = $path;
902 }
903 unset($this->_packageInfo['filelist'][$file]['installed_as']);
904 }
905
906 function installedFile($file, $atts)
907 {
908 if (isset($this->_packageInfo['filelist'][$file])) {
909 $this->_packageInfo['filelist'][$file] =
910 array_merge($this->_packageInfo['filelist'][$file], $atts);
911 } else {
912 $this->_packageInfo['filelist'][$file] = $atts;
913 }
914 }
915
916 function getChangelog()
917 {
918 if (isset($this->_packageInfo['changelog'])) {
919 return $this->_packageInfo['changelog'];
920 }
921 return false;
922 }
923
925 {
926 return '1.0';
927 }
928
934 function getValidationWarnings($purge = true)
935 {
936 return $this->_stack->getErrors($purge);
937 }
938
939 // }}}
946 function _validateError($code, $params = array())
947 {
948 $this->_stack->push($code, 'error', $params, false, false, debug_backtrace());
949 $this->_isValid = false;
950 }
951
958 function _validateWarning($code, $params = array())
959 {
960 $this->_stack->push($code, 'warning', $params, false, false, debug_backtrace());
961 }
962
968 {
969 return array(
971 'Missing Package Name',
973 'No summary found',
975 'Summary should be on one line',
977 'Missing description',
979 'Missing license',
981 'No release version found',
983 'No release state found',
985 'No release date found',
987 'No release notes found',
989 'Package must have at least one lead maintainer',
991 'No maintainers found, at least one must be defined',
993 'Maintainer %index% has no handle (user ID at channel server)',
995 'Maintainer %index% has no role',
997 'Maintainer %index% has no name',
999 'Maintainer %index% has no email',
1001 'Dependency %index% is not a php dependency, and has no name',
1003 'Dependency %index% has no relation (rel)',
1005 'Dependency %index% has no type',
1007 'PHP Dependency %index% has a name attribute of "%name%" which will be' .
1008 ' ignored!',
1010 'Dependency %index% is not a rel="has" or rel="not" dependency, ' .
1011 'and has no version',
1013 'Dependency %index% is a type="php" dependency, ' .
1014 'and has no version',
1016 'Dependency %index% is a rel="%rel%" dependency, versioning is ignored',
1018 'Dependency %index% has invalid optional value "%opt%", should be yes or no',
1020 'Dependency %index%: php dependencies cannot use "not" rel, use "ne"' .
1021 ' to exclude specific versions',
1023 'Configure Option %index% has no name',
1025 'Configure Option %index% has no prompt',
1027 'No files in <filelist> section of package.xml',
1029 'File "%file%" has no role, expecting one of "%roles%"',
1031 'File "%file%" has invalid role "%role%", expecting one of "%roles%"',
1033 'File "%file%" cannot start with ".", cannot package or install',
1035 'Parser error: invalid PHP found in file "%file%"',
1037 'in %file%: %type% "%name%" not prefixed with package name "%package%"',
1039 'Parser error: invalid PHP file "%file%"',
1041 'Channel validator error: field "%field%" - %reason%',
1043 'Error, PHP5 token encountered in %file%, analysis should be in PHP5',
1045 'File "%file%" in package.xml does not exist',
1047 'Package.xml contains non-ISO-8859-1 characters, and may not validate',
1048 );
1049 }
1050
1057 function validate($state = PEAR_VALIDATE_NORMAL, $nofilechecking = false)
1058 {
1059 if (($this->_isValid & $state) == $state) {
1060 return true;
1061 }
1062 $this->_isValid = true;
1063 $info = $this->_packageInfo;
1064 if (empty($info['package'])) {
1066 $this->_packageName = $pn = 'unknown';
1067 } else {
1068 $this->_packageName = $pn = $info['package'];
1069 }
1070
1071 if (empty($info['summary'])) {
1073 } elseif (strpos(trim($info['summary']), "\n") !== false) {
1075 array('summary' => $info['summary']));
1076 }
1077 if (empty($info['description'])) {
1079 }
1080 if (empty($info['release_license'])) {
1082 }
1083 if (empty($info['version'])) {
1085 }
1086 if (empty($info['release_state'])) {
1088 }
1089 if (empty($info['release_date'])) {
1091 }
1092 if (empty($info['release_notes'])) {
1094 }
1095 if (empty($info['maintainers'])) {
1097 } else {
1098 $haslead = false;
1099 $i = 1;
1100 foreach ($info['maintainers'] as $m) {
1101 if (empty($m['handle'])) {
1103 array('index' => $i));
1104 }
1105 if (empty($m['role'])) {
1107 array('index' => $i, 'roles' => PEAR_Common::getUserRoles()));
1108 } elseif ($m['role'] == 'lead') {
1109 $haslead = true;
1110 }
1111 if (empty($m['name'])) {
1113 array('index' => $i));
1114 }
1115 if (empty($m['email'])) {
1117 array('index' => $i));
1118 }
1119 $i++;
1120 }
1121 if (!$haslead) {
1123 }
1124 }
1125 if (!empty($info['release_deps'])) {
1126 $i = 1;
1127 foreach ($info['release_deps'] as $d) {
1128 if (!isset($d['type']) || empty($d['type'])) {
1130 array('index' => $i, 'types' => PEAR_Common::getDependencyTypes()));
1131 continue;
1132 }
1133 if (!isset($d['rel']) || empty($d['rel'])) {
1135 array('index' => $i, 'rels' => PEAR_Common::getDependencyRelations()));
1136 continue;
1137 }
1138 if (!empty($d['optional'])) {
1139 if (!in_array($d['optional'], array('yes', 'no'))) {
1141 array('index' => $i, 'opt' => $d['optional']));
1142 }
1143 }
1144 if ($d['rel'] != 'has' && $d['rel'] != 'not' && empty($d['version'])) {
1146 array('index' => $i));
1147 } elseif (($d['rel'] == 'has' || $d['rel'] == 'not') && !empty($d['version'])) {
1149 array('index' => $i, 'rel' => $d['rel']));
1150 }
1151 if ($d['type'] == 'php' && !empty($d['name'])) {
1153 array('index' => $i, 'name' => $d['name']));
1154 } elseif ($d['type'] != 'php' && empty($d['name'])) {
1156 array('index' => $i));
1157 }
1158 if ($d['type'] == 'php' && empty($d['version'])) {
1160 array('index' => $i));
1161 }
1162 if (($d['rel'] == 'not') && ($d['type'] == 'php')) {
1164 array('index' => $i));
1165 }
1166 $i++;
1167 }
1168 }
1169 if (!empty($info['configure_options'])) {
1170 $i = 1;
1171 foreach ($info['configure_options'] as $c) {
1172 if (empty($c['name'])) {
1174 array('index' => $i));
1175 }
1176 if (empty($c['prompt'])) {
1178 array('index' => $i));
1179 }
1180 $i++;
1181 }
1182 }
1183 if (empty($info['filelist'])) {
1185 $errors[] = 'no files';
1186 } else {
1187 foreach ($info['filelist'] as $file => $fa) {
1188 if (empty($fa['role'])) {
1190 array('file' => $file, 'roles' => PEAR_Common::getFileRoles()));
1191 continue;
1192 } elseif (!in_array($fa['role'], PEAR_Common::getFileRoles())) {
1194 array('file' => $file, 'role' => $fa['role'], 'roles' => PEAR_Common::getFileRoles()));
1195 }
1196 if (preg_match('~/\.\.?(/|\\z)|^\.\.?/~', str_replace('\\', '/', $file))) {
1197 // file contains .. parent directory or . cur directory references
1199 array('file' => $file));
1200 }
1201 if (isset($fa['install-as']) &&
1202 preg_match('~/\.\.?(/|\\z)|^\.\.?/~',
1203 str_replace('\\', '/', $fa['install-as']))) {
1204 // install-as contains .. parent directory or . cur directory references
1206 array('file' => $file . ' [installed as ' . $fa['install-as'] . ']'));
1207 }
1208 if (isset($fa['baseinstalldir']) &&
1209 preg_match('~/\.\.?(/|\\z)|^\.\.?/~',
1210 str_replace('\\', '/', $fa['baseinstalldir']))) {
1211 // install-as contains .. parent directory or . cur directory references
1213 array('file' => $file . ' [baseinstalldir ' . $fa['baseinstalldir'] . ']'));
1214 }
1215 }
1216 }
1217 if (isset($this->_registry) && $this->_isValid) {
1218 $chan = $this->_registry->getChannel('pear.php.net');
1219 if (PEAR::isError($chan)) {
1220 $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $chan->getMessage());
1221 return $this->_isValid = 0;
1222 }
1223 $validator = $chan->getValidationObject();
1224 $validator->setPackageFile($this);
1225 $validator->validate($state);
1226 $failures = $validator->getFailures();
1227 foreach ($failures['errors'] as $error) {
1229 }
1230 foreach ($failures['warnings'] as $warning) {
1232 }
1233 }
1234 if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$nofilechecking) {
1235 if ($this->_analyzePhpFiles()) {
1236 $this->_isValid = true;
1237 }
1238 }
1239 if ($this->_isValid) {
1240 return $this->_isValid = $state;
1241 }
1242 return $this->_isValid = 0;
1243 }
1244
1246 {
1247 if (!$this->_isValid) {
1248 return false;
1249 }
1250 if (!isset($this->_packageFile)) {
1251 return false;
1252 }
1253 $dir_prefix = dirname($this->_packageFile);
1254 $common = new PEAR_Common;
1255 $log = isset($this->_logger) ? array(&$this->_logger, 'log') :
1256 array($common, 'log');
1257 $info = $this->getFilelist();
1258 foreach ($info as $file => $fa) {
1259 if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $file)) {
1261 array('file' => realpath($dir_prefix) . DIRECTORY_SEPARATOR . $file));
1262 continue;
1263 }
1264 if ($fa['role'] == 'php' && $dir_prefix) {
1265 call_user_func_array($log, array(1, "Analyzing $file"));
1266 $srcinfo = $this->_analyzeSourceCode($dir_prefix . DIRECTORY_SEPARATOR . $file);
1267 if ($srcinfo) {
1268 $this->_buildProvidesArray($srcinfo);
1269 }
1270 }
1271 }
1272 $this->_packageName = $pn = $this->getPackage();
1273 $pnl = strlen($pn);
1274 if (isset($this->_packageInfo['provides'])) {
1275 foreach ((array) $this->_packageInfo['provides'] as $key => $what) {
1276 if (isset($what['explicit'])) {
1277 // skip conformance checks if the provides entry is
1278 // specified in the package.xml file
1279 continue;
1280 }
1281 extract($what);
1282 if ($type == 'class') {
1283 if (!strncasecmp($name, $pn, $pnl)) {
1284 continue;
1285 }
1287 array('file' => $file, 'type' => $type, 'name' => $name, 'package' => $pn));
1288 } elseif ($type == 'function') {
1289 if (strstr($name, '::') || !strncasecmp($name, $pn, $pnl)) {
1290 continue;
1291 }
1293 array('file' => $file, 'type' => $type, 'name' => $name, 'package' => $pn));
1294 }
1295 }
1296 }
1297 return $this->_isValid;
1298 }
1299
1306 {
1307 if (!class_exists('PEAR_PackageFile_Generator_v1')) {
1308 require_once 'PEAR/PackageFile/Generator/v1.php';
1309 }
1310 $a = new PEAR_PackageFile_Generator_v1($this);
1311 return $a;
1312 }
1313
1319 function getFileContents($file)
1320 {
1321 if ($this->_archiveFile == $this->_packageFile) { // unpacked
1322 $dir = dirname($this->_packageFile);
1323 $file = $dir . DIRECTORY_SEPARATOR . $file;
1324 $file = str_replace(array('/', '\\'),
1325 array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $file);
1326 if (file_exists($file) && is_readable($file)) {
1327 return implode('', file($file));
1328 }
1329 } else { // tgz
1330 if (!class_exists('Archive_Tar')) {
1331 require_once 'Archive/Tar.php';
1332 }
1333 $tar = new Archive_Tar($this->_archiveFile);
1334 $tar->pushErrorHandling(PEAR_ERROR_RETURN);
1335 if ($file != 'package.xml' && $file != 'package2.xml') {
1336 $file = $this->getPackage() . '-' . $this->getVersion() . '/' . $file;
1337 }
1338 $file = $tar->extractInString($file);
1339 $tar->popErrorHandling();
1340 if (PEAR::isError($file)) {
1341 return PEAR::raiseError("Cannot locate file '$file' in archive");
1342 }
1343 return $file;
1344 }
1345 }
1346
1347 // {{{ analyzeSourceCode()
1355 function _analyzeSourceCode($file)
1356 {
1357 if (!function_exists("token_get_all")) {
1358 return false;
1359 }
1360 if (!defined('T_DOC_COMMENT')) {
1361 define('T_DOC_COMMENT', T_COMMENT);
1362 }
1363 if (!defined('T_INTERFACE')) {
1364 define('T_INTERFACE', -1);
1365 }
1366 if (!defined('T_IMPLEMENTS')) {
1367 define('T_IMPLEMENTS', -1);
1368 }
1369 if (!$fp = @fopen($file, "r")) {
1370 return false;
1371 }
1372 fclose($fp);
1373 $contents = file_get_contents($file);
1374 $tokens = token_get_all($contents);
1375/*
1376 for ($i = 0; $i < sizeof($tokens); $i++) {
1377 @list($token, $data) = $tokens[$i];
1378 if (is_string($token)) {
1379 var_dump($token);
1380 } else {
1381 print token_name($token) . ' ';
1382 var_dump(rtrim($data));
1383 }
1384 }
1385*/
1386 $look_for = 0;
1387 $paren_level = 0;
1388 $bracket_level = 0;
1389 $brace_level = 0;
1390 $lastphpdoc = '';
1391 $current_class = '';
1392 $current_interface = '';
1393 $current_class_level = -1;
1394 $current_function = '';
1395 $current_function_level = -1;
1396 $declared_classes = array();
1397 $declared_interfaces = array();
1398 $declared_functions = array();
1399 $declared_methods = array();
1400 $used_classes = array();
1401 $used_functions = array();
1402 $extends = array();
1403 $implements = array();
1404 $nodeps = array();
1405 $inquote = false;
1406 $interface = false;
1407 for ($i = 0; $i < sizeof($tokens); $i++) {
1408 if (is_array($tokens[$i])) {
1409 list($token, $data) = $tokens[$i];
1410 } else {
1411 $token = $tokens[$i];
1412 $data = '';
1413 }
1414 if ($inquote) {
1415 if ($token != '"' && $token != T_END_HEREDOC) {
1416 continue;
1417 } else {
1418 $inquote = false;
1419 continue;
1420 }
1421 }
1422 switch ($token) {
1423 case T_WHITESPACE:
1424 break;
1425 case ';':
1426 if ($interface) {
1427 $current_function = '';
1428 $current_function_level = -1;
1429 }
1430 break;
1431 case '"':
1432 case T_START_HEREDOC:
1433 $inquote = true;
1434 break;
1435 case T_CURLY_OPEN:
1436 case T_DOLLAR_OPEN_CURLY_BRACES:
1437 case '{': $brace_level++; continue 2;
1438 case '}':
1439 $brace_level--;
1440 if ($current_class_level == $brace_level) {
1441 $current_class = '';
1442 $current_class_level = -1;
1443 }
1444 if ($current_function_level == $brace_level) {
1445 $current_function = '';
1446 $current_function_level = -1;
1447 }
1448 continue 2;
1449 case '[': $bracket_level++; continue 2;
1450 case ']': $bracket_level--; continue 2;
1451 case '(': $paren_level++; continue 2;
1452 case ')': $paren_level--; continue 2;
1453 case T_INTERFACE:
1454 $interface = true;
1455 case T_CLASS:
1456 if (($current_class_level != -1) || ($current_function_level != -1)) {
1458 array('file' => $file));
1459 return false;
1460 }
1461 case T_FUNCTION:
1462 case T_NEW:
1463 case T_EXTENDS:
1464 case T_IMPLEMENTS:
1465 $look_for = $token;
1466 continue 2;
1467 case T_STRING:
1468 if ($look_for == T_CLASS) {
1469 $current_class = $data;
1470 $current_class_level = $brace_level;
1471 $declared_classes[] = $current_class;
1472 } elseif ($look_for == T_INTERFACE) {
1473 $current_interface = $data;
1474 $current_class_level = $brace_level;
1475 $declared_interfaces[] = $current_interface;
1476 } elseif ($look_for == T_IMPLEMENTS) {
1477 $implements[$current_class] = $data;
1478 } elseif ($look_for == T_EXTENDS) {
1479 $extends[$current_class] = $data;
1480 } elseif ($look_for == T_FUNCTION) {
1481 if ($current_class) {
1482 $current_function = "$current_class::$data";
1483 $declared_methods[$current_class][] = $data;
1484 } elseif ($current_interface) {
1485 $current_function = "$current_interface::$data";
1486 $declared_methods[$current_interface][] = $data;
1487 } else {
1488 $current_function = $data;
1489 $declared_functions[] = $current_function;
1490 }
1491 $current_function_level = $brace_level;
1492 $m = array();
1493 } elseif ($look_for == T_NEW) {
1494 $used_classes[$data] = true;
1495 }
1496 $look_for = 0;
1497 continue 2;
1498 case T_VARIABLE:
1499 $look_for = 0;
1500 continue 2;
1501 case T_DOC_COMMENT:
1502 case T_COMMENT:
1503 if (preg_match('!^/\*\*\s!', $data)) {
1504 $lastphpdoc = $data;
1505 if (preg_match_all('/@nodep\s+(\S+)/', $lastphpdoc, $m)) {
1506 $nodeps = array_merge($nodeps, $m[1]);
1507 }
1508 }
1509 continue 2;
1510 case T_DOUBLE_COLON:
1511 if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
1513 array('file' => $file));
1514 return false;
1515 }
1516 $class = $tokens[$i - 1][1];
1517 if (strtolower($class) != 'parent') {
1518 $used_classes[$class] = true;
1519 }
1520 continue 2;
1521 }
1522 }
1523 return array(
1524 "source_file" => $file,
1525 "declared_classes" => $declared_classes,
1526 "declared_interfaces" => $declared_interfaces,
1527 "declared_methods" => $declared_methods,
1528 "declared_functions" => $declared_functions,
1529 "used_classes" => array_diff(array_keys($used_classes), $nodeps),
1530 "inheritance" => $extends,
1531 "implements" => $implements,
1532 );
1533 }
1534
1554 function _buildProvidesArray($srcinfo)
1555 {
1556 if (!$this->_isValid) {
1557 return false;
1558 }
1559 $file = basename($srcinfo['source_file']);
1560 $pn = $this->getPackage();
1561 $pnl = strlen($pn);
1562 foreach ($srcinfo['declared_classes'] as $class) {
1563 $key = "class;$class";
1564 if (isset($this->_packageInfo['provides'][$key])) {
1565 continue;
1566 }
1567 $this->_packageInfo['provides'][$key] =
1568 array('file'=> $file, 'type' => 'class', 'name' => $class);
1569 if (isset($srcinfo['inheritance'][$class])) {
1570 $this->_packageInfo['provides'][$key]['extends'] =
1571 $srcinfo['inheritance'][$class];
1572 }
1573 }
1574 foreach ($srcinfo['declared_methods'] as $class => $methods) {
1575 foreach ($methods as $method) {
1576 $function = "$class::$method";
1577 $key = "function;$function";
1578 if ($method[0] == '_' || !strcasecmp($method, $class) ||
1579 isset($this->_packageInfo['provides'][$key])) {
1580 continue;
1581 }
1582 $this->_packageInfo['provides'][$key] =
1583 array('file'=> $file, 'type' => 'function', 'name' => $function);
1584 }
1585 }
1586
1587 foreach ($srcinfo['declared_functions'] as $function) {
1588 $key = "function;$function";
1589 if ($function[0] == '_' || isset($this->_packageInfo['provides'][$key])) {
1590 continue;
1591 }
1592 if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {
1593 $warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";
1594 }
1595 $this->_packageInfo['provides'][$key] =
1596 array('file'=> $file, 'type' => 'function', 'name' => $function);
1597 }
1598 }
1599
1600 // }}}
1601}
1602?>
const PEAR_ERROR_RETURN
Definition PEAR.php:24
const PEAR_VALIDATE_PACKAGING
Definition Validate.php:22
const PEAR_VALIDATE_NORMAL
Definition Validate.php:20
static getFileRoles()
Definition Common.php:365
static getDependencyTypes()
Definition Common.php:345
static getDependencyRelations()
Definition Common.php:355
static getUserRoles()
Definition Common.php:325
setRawPackage($package)
Definition v1.php:538
setLicense($date)
Definition v1.php:667
setPackagefile($file, $archive=false)
Definition v1.php:421
_buildProvidesArray($srcinfo)
Definition v1.php:1554
isExtension($name)
Definition v1.php:360
getDependencyGroup($group)
Definition v1.php:779
fromArray($pinfo)
Definition v1.php:472
setSummary($summary)
Definition v1.php:681
setDate($date)
Definition v1.php:653
addMaintainer($role, $handle, $name, $email)
Definition v1.php:580
addPackageDep($name, $version, $rel, $optional='no')
Definition v1.php:740
deleteMaintainer($handle)
Definition v1.php:608
addExtensionDep($name, $version, $rel, $optional='no')
Definition v1.php:754
packageInfo($field)
Definition v1.php:442
initPostinstallScripts()
Definition v1.php:408
setNotes($notes)
Definition v1.php:709
setLogger(&$logger)
Definition v1.php:413
setFileAttribute($file, $attr, $value)
Definition v1.php:888
setDirtree($path)
Definition v1.php:451
setVersion($version)
Definition v1.php:557
getFileContents($file)
Definition v1.php:1319
_validateError($code, $params=array())
Definition v1.php:946
addConfigureOption($name, $prompt, $default=false)
Definition v1.php:832
updateMaintainer($role, $handle, $name, $email)
Definition v1.php:587
setConfig(&$config)
Definition v1.php:365
setDescription($desc)
Definition v1.php:695
setState($state)
Definition v1.php:639
listPostinstallScripts()
Definition v1.php:403
setDeps($deps)
Definition v1.php:768
_analyzeSourceCode($file)
Definition v1.php:1355
getInstallationFilelist()
Definition v1.php:875
getValidationWarnings($purge=true)
Definition v1.php:934
installBinary($installer)
Definition v1.php:355
setRawState($state)
Definition v1.php:634
_validateWarning($code, $params=array())
Definition v1.php:958
setPackage($package)
Definition v1.php:543
addFile($dir, $file, $attrs)
Definition v1.php:862
addPhpDep($version, $rel)
Definition v1.php:731
setInstalledAs($file, $path)
Definition v1.php:898
setLastInstalledVersion($version)
Definition v1.php:382
dependsOn($package, $channel)
Definition v1.php:799
installedFile($file, $atts)
Definition v1.php:906
clearConfigureOptions()
Definition v1.php:844
getLastInstalledVersion()
Definition v1.php:390
& getDefaultGenerator()
Definition v1.php:1305
validate($state=PEAR_VALIDATE_NORMAL, $nofilechecking=false)
Definition v1.php:1057
isCompatible($pf)
Definition v1.php:784
$config
Definition pearcmd.php:182
const PEAR_PACKAGEFILE_ERROR_INVALID_DEPOPTIONAL
Definition v1.php:163
const PEAR_PACKAGEFILE_ERROR_NO_MAINTNAME
Definition v1.php:118
const PEAR_PACKAGEFILE_ERROR_FILE_NOTFOUND
Definition v1.php:244
const PEAR_PACKAGEFILE_ERROR_NO_DESCRIPTION
Definition v1.php:58
const PEAR_PACKAGEFILE_ERROR_NO_DATE
Definition v1.php:88
const PEAR_PACKAGEFILE_ERROR_NO_SUMMARY
Definition v1.php:48
const PEAR_PACKAGEFILE_ERROR_NO_DEPREL
Definition v1.php:143
const PEAR_PACKAGEFILE_ERROR_PHP5
Definition v1.php:239
const PEAR_PACKAGEFILE_PHP_NO_NOT
Definition v1.php:249
const PEAR_PACKAGEFILE_ERROR_NO_MAINTROLE
Definition v1.php:113
const PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX
Definition v1.php:214
const PEAR_PACKAGEFILE_ERROR_NO_LICENSE
Definition v1.php:63
const PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE
Definition v1.php:198
const PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME
Definition v1.php:269
const PEAR_PACKAGEFILE_ERROR_DEPNAME_IGNORED
Definition v1.php:183
const PEAR_PACKAGEFILE_ERROR_NO_MAINTEMAIL
Definition v1.php:123
const PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE
Definition v1.php:208
const PEAR_PACKAGEFILE_ERROR_NO_MAINTAINERS
Definition v1.php:103
const PEAR_PACKAGEFILE_ERROR_NO_DEPTYPE
Definition v1.php:138
const PEAR_PACKAGEFILE_ERROR_NO_DEPPHPVERSION
Definition v1.php:259
const PEAR_PACKAGEFILE_ERROR_CHANNELVAL
Definition v1.php:234
const PEAR_PACKAGEFILE_ERROR_NON_ISO_CHARS
Definition v1.php:254
const PEAR_PACKAGEFILE_ERROR_NO_FILES
Definition v1.php:224
const PEAR_PACKAGEFILE_ERROR_INVALID_FILE
Definition v1.php:229
const PEAR_PACKAGEFILE_ERROR_NO_CONFPROMPT
Definition v1.php:193
const PEAR_PACKAGEFILE_ERROR_DEPVERSION_IGNORED
Definition v1.php:178
const PEAR_PACKAGEFILE_ERROR_NO_DEPNAME
Definition v1.php:133
const PEAR_PACKAGEFILE_ERROR_NO_MAINTHANDLE
Definition v1.php:108
const PEAR_PACKAGEFILE_ERROR_NO_FILEROLE
Definition v1.php:203
const PEAR_PACKAGEFILE_ERROR_NO_LEAD
Definition v1.php:264
const PEAR_PACKAGEFILE_ERROR_NO_NAME
Definition v1.php:38
const PEAR_PACKAGEFILE_ERROR_NO_NOTES
Definition v1.php:98
const PEAR_PACKAGEFILE_ERROR_NO_VERSION
Definition v1.php:68
const PEAR_PACKAGEFILE_ERROR_MULTILINE_SUMMARY
Definition v1.php:53
const PEAR_PACKAGEFILE_ERROR_NO_DEPVERSION
Definition v1.php:148
const PEAR_PACKAGEFILE_ERROR_NO_STATE
Definition v1.php:78
const PEAR_PACKAGEFILE_ERROR_NO_CONFNAME
Definition v1.php:188