2 namespace wcf\system\package
;
3 use wcf\data\application\Application
;
4 use wcf\data\application\ApplicationEditor
;
5 use wcf\data\language\category\LanguageCategory
;
6 use wcf\data\language\LanguageEditor
;
7 use wcf\data\language\LanguageList
;
8 use wcf\data\option\OptionEditor
;
9 use wcf\data\package\installation\queue\PackageInstallationQueue
;
10 use wcf\data\package\installation\queue\PackageInstallationQueueEditor
;
11 use wcf\data\package\Package
;
12 use wcf\data\package\PackageEditor
;
13 use wcf\system\cache\CacheHandler
;
14 use wcf\system\database\statement\PreparedStatement
;
15 use wcf\system\database\util\PreparedStatementConditionBuilder
;
16 use wcf\system\exception\SystemException
;
17 use wcf\system\form\container
;
18 use wcf\system\form\element
;
19 use wcf\system\form\FormDocument
;
21 use wcf\system\language\LanguageFactory
;
22 use wcf\system\menu\acp\ACPMenu
;
23 use wcf\system\request\LinkHandler
;
24 use wcf\system\request\RouteHandler
;
26 use wcf\util\FileUtil
;
27 use wcf\util\HeaderUtil
;
28 use wcf\util\StringUtil
;
31 * PackageInstallationDispatcher handles the whole installation process.
33 * @author Alexander Ebert
34 * @copyright 2001-2012 WoltLab GmbH
35 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
36 * @package com.woltlab.wcf
37 * @subpackage system.package
38 * @category Community Framework
40 class PackageInstallationDispatcher
{
42 * current installation type
45 protected $action = '';
48 * instance of PackageArchive
49 * @var wcf\system\package\PackageArchive
51 public $archive = null;
54 * instance of PackageInstallationNodeBuilder
55 * @var wcf\system\package\PackageInstallationNodeBuilder
57 public $nodeBuilder = null;
61 * @var wcf\data\package\Package
63 public $package = null;
66 * instance of PackageInstallationQueue
67 * @var wcf\system\package\PackageInstallationQueue
72 * default name of the config file
75 const CONFIG_FILE
= 'config.inc.php';
78 * Creates a new instance of PackageInstallationDispatcher.
80 * @param wcf\data\package\installation\queue\PackageInstallationQueue $queue
82 public function __construct(PackageInstallationQueue
$queue) {
83 $this->queue
= $queue;
84 $this->nodeBuilder
= new PackageInstallationNodeBuilder($this);
86 $this->action
= $this->queue
->action
;
90 * Installs node components and returns next node.
93 * @return PackageInstallationStep
95 public function install($node) {
96 $nodes = $this->nodeBuilder
->getNodeData($node);
98 // invoke node-specific actions
99 foreach ($nodes as $data) {
100 $nodeData = unserialize($data['nodeData']);
102 switch ($data['nodeType']) {
104 $step = $this->installPackage($nodeData);
108 $step = $this->executePIP($nodeData);
111 case 'optionalPackages':
112 $step = $this->selectOptionalPackages($node, $nodeData);
116 die("Unknown node type: '".$data['nodeType']."'");
120 if ($step->splitNode()) {
121 $this->nodeBuilder
->cloneNode($node, $data['sequenceNo']);
126 // mark node as completed
127 $this->nodeBuilder
->completeNode($node);
130 $node = $this->nodeBuilder
->getNextNode($node);
131 $step->setNode($node);
133 // update options.inc.php and save localized package infos
135 OptionEditor
::resetCache();
137 if ($this->action
== 'install') {
138 $this->saveLocalizedPackageInfos();
140 // remove all cache files after WCFSetup
142 CacheHandler
::getInstance()->clear(WCF_DIR
.'cache/', 'cache.*.php');
151 * Returns current package archive.
153 * @return PackageArchive
155 public function getArchive() {
156 if ($this->archive
=== null) {
157 $this->archive
= new PackageArchive($this->queue
->archive
, $this->getPackage());
159 if (FileUtil
::isURL($this->archive
->getArchive())) {
160 // get return value and update entry in
161 // package_installation_queue with this value
162 $archive = $this->archive
->downloadArchive();
163 $queueEditor = new PackageInstallationQueueEditor($this->queue
);
164 $queueEditor->update(array(
165 'archive' => $archive
169 $this->archive
->openArchive();
172 return $this->archive
;
176 * Installs current package.
178 * @param array $nodeData
180 protected function installPackage(array $nodeData) {
181 $installationStep = new PackageInstallationStep();
183 // check requirements
184 if (!empty($nodeData['requirements'])) {
185 foreach ($nodeData['requirements'] as $package => $requirementData) {
186 // get existing package
187 if ($requirementData['packageID']) {
188 $sql = "SELECT packageName, packageVersion
189 FROM wcf".WCF_N
."_package
190 WHERE packageID = ?";
191 $statement = WCF
::getDB()->prepareStatement($sql);
192 $statement->execute(array($requirementData['packageID']));
195 // try to find matching package
196 $sql = "SELECT packageName, packageVersion
197 FROM wcf".WCF_N
."_package
199 $statement = WCF
::getDB()->prepareStatement($sql);
200 $statement->execute(array($package));
202 $row = $statement->fetchArray();
204 // package is required but not available
205 if ($row === false) {
206 throw new SystemException("Package '".$package."' is required by '".$nodeData['packageName']."', but is neither installed nor shipped.");
209 // check version requirements
210 if ($requirementData['minVersion']) {
211 if (Package
::compareVersion($row['packageVersion'], $requirementData['minVersion']) < 0) {
212 throw new SystemException("Package '".$nodeData['packageName']."' requires the package '".$row['packageName']."' in version '".$requirementData['minVersion']."', but version '".$row['packageVersion']."'");
217 unset($nodeData['requirements']);
219 if (!$this->queue
->packageID
) {
220 // create package entry
221 $package = PackageEditor
::create($nodeData);
223 // update package id for current queue
224 $queueEditor = new PackageInstallationQueueEditor($this->queue
);
225 $queueEditor->update(array(
226 'packageID' => $package->packageID
229 // save excluded packages
230 if (count($this->getArchive()->getExcludedPackages()) > 0) {
231 $sql = "INSERT INTO wcf".WCF_N
."_package_exclusion
232 (packageID, excludedPackage, excludedPackageVersion)
234 $statement = WCF
::getDB()->prepareStatement($sql);
236 foreach ($this->getArchive()->getExcludedPackages() as $excludedPackage) {
237 $statement->execute(array($package->packageID
, $excludedPackage['name'], (!empty($excludedPackage['version']) ?
$excludedPackage['version'] : '')));
241 // if package is plugin to com.woltlab.wcf it must not have any other requirement
242 $requirements = $this->getArchive()->getRequirements();
243 if ($package->parentPackageID
== 1 && count($requirements)) {
244 foreach ($requirements as $package => $data) {
245 if ($package == 'com.woltlab.wcf') continue;
246 throw new SystemException('Package '.$package->package
.' is plugin of com.woltlab.wcf (WCF) but has more than one requirement.');
250 // insert requirements and dependencies
251 $requirements = $this->getArchive()->getAllExistingRequirements();
252 if (count($requirements) > 0) {
253 $sql = "INSERT INTO wcf".WCF_N
."_package_requirement
254 (packageID, requirement)
256 $statement = WCF
::getDB()->prepareStatement($sql);
258 foreach ($requirements as $identifier => $possibleRequirements) {
259 if (count($possibleRequirements) == 1) $requirement = array_shift($possibleRequirements);
261 $requirement = $possibleRequirements[$this->selectedRequirements
[$identifier]];
264 $statement->execute(array($package->packageID
, $requirement['packageID']));
268 // build requirement map
269 Package
::rebuildPackageRequirementMap($package->packageID
);
271 // rebuild dependencies
272 Package
::rebuildPackageDependencies($package->packageID
);
273 if ($this->action
== 'update') {
274 Package
::rebuildParentPackageDependencies($package->packageID
);
278 $this->queue
= new PackageInstallationQueue($this->queue
->queueID
);
279 $this->package
= null;
281 if ($package->isApplication
) {
282 $host = StringUtil
::replace(RouteHandler
::getProtocol(), '', RouteHandler
::getHost());
283 $path = RouteHandler
::getPath(array('acp'));
285 // insert as application
286 ApplicationEditor
::create(array(
287 'domainName' => $host,
288 'domainPath' => $path,
289 'packageID' => $package->packageID
293 // insert dependencies on parent package if applicable
294 $this->installPackageParent();
297 if ($this->getPackage()->isApplication
&& $this->getPackage()->package
!= 'com.woltlab.wcf' && $this->getAction() == 'install') {
298 if (empty($this->getPackage()->packageDir
)) {
299 $document = $this->promptPackageDir();
300 if ($document !== null && $document instanceof form\FormDocument
) {
301 $installationStep->setDocument($document);
304 $installationStep->setSplitNode();
307 else if ($this->getPackage()->parentPackageID
) {
308 $packageEditor = new PackageEditor($this->getPackage());
309 $packageEditor->update(array(
310 'packageDir' => $this->getPackage()->getParentPackage()->packageDir
314 return $installationStep;
318 * Saves the localized package infos.
320 * @todo license and readme
322 protected function saveLocalizedPackageInfos() {
323 $package = new Package($this->queue
->packageID
);
325 // localize package information
326 $sql = "INSERT INTO wcf".WCF_N
."_language_item
327 (languageID, languageItem, languageItemValue, languageCategoryID, packageID)
328 VALUES (?, ?, ?, ?, ?)";
329 $statement = WCF
::getDB()->prepareStatement($sql);
332 $languageList = new LanguageList();
333 $languageList->sqlLimit
= 0;
334 $languageList->readObjects();
336 // workaround for WCFSetup
339 FROM wcf".WCF_N
."_language_category
340 WHERE languageCategory = ?";
341 $statement2 = WCF
::getDB()->prepareStatement($sql);
342 $statement2->execute(array('wcf.acp.package'));
343 $languageCategory = $statement2->fetchObject('wcf\data\language\category\LanguageCategory');
346 $languageCategory = LanguageFactory
::getInstance()->getCategory('wcf.acp.package');
350 $this->saveLocalizedPackageInfo($statement, $languageList, $languageCategory, $package, 'packageName');
352 // save package description
353 $this->saveLocalizedPackageInfo($statement, $languageList, $languageCategory, $package, 'packageDescription');
355 // update description and name
356 $packageEditor = new PackageEditor($package);
357 $packageEditor->update(array(
358 'packageDescription' => 'wcf.acp.package.packageDescription.package'.$this->queue
->packageID
,
359 'packageName' => 'wcf.acp.package.packageName.package'.$this->queue
->packageID
364 * Saves a localized package info.
366 * @param wcf\system\database\statement\PreparedStatement $statement
367 * @param wcf\data\language\LanguageList $languageList
368 * @param wcf\data\language\category\LanguageCategory $languageCategory
369 * @param wcf\data\package\Package $package
370 * @param string $infoName
372 protected function saveLocalizedPackageInfo(PreparedStatement
$statement, $languageList, LanguageCategory
$languageCategory, Package
$package, $infoName) {
373 $infoValues = $this->getArchive()->getPackageInfo($infoName);
375 // get default value for languages without specified information
377 if (isset($infoValues['default'])) {
378 $defaultValue = $infoValues['default'];
380 else if (isset($infoValues['en'])) {
381 // fallback to English
382 $defaultValue = $infoValues['en'];
384 else if (isset($infoValues[WCF
::getLanguage()->getFixedLanguageCode()])) {
385 // fallback to the language of the current user
386 $defaultValue = $infoValues[WCF
::getLanguage()->getFixedLanguageCode()];
388 else if ($infoName == 'packageName') {
389 // fallback to the package identifier for the package name
390 $defaultValue = $this->archive
->getPackageInfo('name');
393 foreach ($languageList as $language) {
394 $value = $defaultValue;
395 if (isset($infoValues[$language->languageCode
])) {
396 $value = $infoValues[$language->languageCode
];
399 $statement->execute(array(
400 $language->languageID
,
401 'wcf.acp.package.'.$infoName.'.package'.$package->packageID
,
403 $languageCategory->languageCategoryID
,
410 * Sets parent package and rebuilds dependencies for both.
412 protected function installPackageParent() {
413 // do not handle parent package if current package is an application or does not have a plugin tag while within installation process
414 if ($this->getArchive()->getPackageInfo('isApplication') ||
$this->getAction() != 'install' ||
!$this->getArchive()->getPackageInfo('plugin')) {
418 // get parent package from requirements
419 $sql = "SELECT requirement
420 FROM wcf".WCF_N
."_package_requirement
424 FROM wcf".WCF_N
."_package
427 $statement = WCF
::getDB()->prepareStatement($sql);
428 $statement->execute(array(
429 $this->getPackage()->packageID
,
430 $this->getArchive()->getPackageInfo('plugin')
432 $row = $statement->fetchArray();
433 if (!$row ||
empty($row['requirement'])) {
434 throw new SystemException("can not find any available installations of required parent package '".$this->getArchive()->getPackageInfo('plugin')."'");
437 // save parent package
438 $packageEditor = new PackageEditor($this->getPackage());
439 $packageEditor->update(array(
440 'parentPackageID' => $row['requirement']
443 // rebuild parent package dependencies
444 Package
::rebuildParentPackageDependencies($this->getPackage()->packageID
);
446 // rebuild parent's parent package dependencies
447 Package
::rebuildParentPackageDependencies($row['requirement']);
449 // reload package object on next request
450 $this->package
= null;
454 * Executes a package installation plugin.
459 protected function executePIP(array $nodeData) {
460 $step = new PackageInstallationStep();
462 // fetch all pips associated with current PACKAGE_ID and include pips
463 // previously installed by current installation queue
464 $sql = "SELECT pluginName, className
465 FROM wcf".WCF_N
."_package_installation_plugin
466 WHERE pluginName = ?";
467 $statement = WCF
::getDB()->prepareStatement($sql);
468 $statement->execute(array(
471 $row = $statement->fetchArray();
474 if (!$row ||
(strcmp($nodeData['pip'], $row['pluginName']) !== 0)) {
475 throw new SystemException("unable to find package installation plugin '".$nodeData['pip']."'");
478 // valdidate class definition
479 $className = $row['className'];
480 if (!class_exists($className)) {
481 throw new SystemException("unable to find class '".$className."'");
484 $plugin = new $className($this, $nodeData);
486 if (!($plugin instanceof \wcf\system\package\plugin\IPackageInstallationPlugin
)) {
487 throw new SystemException("'".$className."' does not implement 'wcf\system\package\plugin\IPackageInstallationPlugin'");
492 $document = $plugin->{$this->action
}();
494 catch (SplitNodeException
$e) {
495 $step->setSplitNode();
498 if ($document !== null && ($document instanceof FormDocument
)) {
499 $step->setDocument($document);
500 $step->setSplitNode();
506 protected function selectOptionalPackages($currentNode, array $nodeData) {
507 $installationStep = new PackageInstallationStep();
509 $document = $this->promptOptionalPackages($nodeData);
510 if ($document !== null && $document instanceof form\FormDocument
) {
511 $installationStep->setDocument($document);
512 $installationStep->setSplitNode();
514 // insert new nodes for each package
515 else if (is_array($document)) {
516 // get target child node
517 $node = $currentNode;
518 $queue = $this->queue
;
521 foreach ($nodeData as $package) {
522 if (in_array($package['package'], $document)) {
524 $this->nodeBuilder
->shiftNodes($currentNode, 'tempNode');
528 $queue = PackageInstallationQueueEditor
::create(array(
529 'parentQueueID' => $queue->queueID
,
530 'processNo' => $this->queue
->processNo
,
531 'userID' => WCF
::getUser()->userID
,
532 'package' => $package['package'],
533 'packageName' => $package['packageName'],
534 'archive' => $package['archive'],
535 'action' => $queue->action
538 $installation = new PackageInstallationDispatcher($queue);
539 $installation->nodeBuilder
->setParentNode($node);
540 $installation->nodeBuilder
->buildNodes();
541 $node = $installation->nodeBuilder
->getCurrentNode();
547 $this->nodeBuilder
->shiftNodes('tempNode', $node);
551 return $installationStep;
555 * Extracts files from .tar (or .tar.gz) archive and installs them
557 * @param string $targetDir
558 * @param string $sourceArchive
559 * @param FileHandler $fileHandler
560 * @return wcf\system\setup\Installer
562 public function extractFiles($targetDir, $sourceArchive, $fileHandler = null) {
563 return new \wcf\system\setup\
Installer($targetDir, $sourceArchive, $fileHandler);
567 * Returns current package.
569 * @return wcf\data\package\Package
571 public function getPackage() {
572 if ($this->package
=== null) {
573 $this->package
= new Package($this->queue
->packageID
);
576 return $this->package
;
580 * Prompts for a text input for package directory (applies for applications only)
582 * @return wcf\system\form\FormDocument
584 protected function promptPackageDir() {
585 if (!PackageInstallationFormManager
::findForm($this->queue
, 'packageDir')) {
587 $container = new container\
GroupFormElementContainer();
588 $packageDir = new element\
TextInputFormElement($container);
589 $packageDir->setName('packageDir');
590 $packageDir->setLabel(WCF
::getLanguage()->get('wcf.acp.package.packageDir.input'));
592 $path = RouteHandler
::getPath(array('wcf', 'acp'));
593 $defaultPath = FileUtil
::addTrailingSlash(FileUtil
::unifyDirSeperator($_SERVER['DOCUMENT_ROOT'] . $path));
594 $packageDir->setValue($defaultPath);
595 $container->appendChild($packageDir);
597 $document = new form\
FormDocument('packageDir');
598 $document->appendContainer($container);
600 PackageInstallationFormManager
::registerForm($this->queue
, $document);
604 $document = PackageInstallationFormManager
::getForm($this->queue
, 'packageDir');
605 $document->handleRequest();
606 $packageDir = $document->getValue('packageDir');
608 if ($packageDir !== null) {
609 // validate package dir
610 if (file_exists(FileUtil
::addTrailingSlash($packageDir) . 'global.php')) {
611 $document->setError('packageDir', WCF
::getLanguage()->get('wcf.acp.package.packageDir.notAvailable'));
616 $packageEditor = new PackageEditor($this->getPackage());
617 $packageEditor->update(array(
618 'packageDir' => FileUtil
::getRelativePath(WCF_DIR
, $packageDir)
622 $domainPath = FileUtil
::getRelativePath(FileUtil
::unifyDirSeperator($_SERVER['DOCUMENT_ROOT']), FileUtil
::unifyDirSeperator($packageDir));
623 $domainPath = FileUtil
::addLeadingSlash(FileUtil
::addTrailingSlash($domainPath));
625 // update application path
626 $application = new Application($this->getPackage()->packageID
);
627 $applicationEditor = new ApplicationEditor($application);
628 $applicationEditor->update(array(
629 'domainPath' => $domainPath
632 // create directory and set permissions
633 @mkdir
($packageDir, 0777, true);
634 @chmod
($packageDir, 0777);
641 protected function promptOptionalPackages(array $packages) {
642 if (!PackageInstallationFormManager
::findForm($this->queue
, 'optionalPackages')) {
643 $container = new container\
MultipleSelectionFormElementContainer();
644 $container->setName('optionalPackages');
646 foreach ($packages as $package) {
647 $optionalPackage = new element\
MultipleSelectionFormElement($container);
648 $optionalPackage->setName('optionalPackages');
649 $optionalPackage->setLabel($package['packageName']);
650 $optionalPackage->setValue($package['package']);
652 $container->appendChild($optionalPackage);
655 $document = new form\
FormDocument('optionalPackages');
656 $document->appendContainer($container);
658 PackageInstallationFormManager
::registerForm($this->queue
, $document);
662 $document = PackageInstallationFormManager
::getForm($this->queue
, 'optionalPackages');
663 $document->handleRequest();
665 return $document->getValue('optionalPackages');
670 * Returns current package id.
674 public function getPackageID() {
675 return $this->queue
->packageID
;
679 * Returns current package installation type.
683 public function getAction() {
684 return $this->action
;
688 * Opens the package installation queue and
689 * starts the installation, update or uninstallation of the first entry.
691 * @param integer $parentQueueID
692 * @param integer $processNo
694 public static function openQueue($parentQueueID = 0, $processNo = 0) {
695 $conditions = new PreparedStatementConditionBuilder();
696 $conditions->add("userID = ?", array(WCF
::getUser()->userID
));
697 $conditions->add("parentQueueID = ?", array($parentQueueID));
698 if ($processNo != 0) $conditions->add("processNo = ?", array($processNo));
699 $conditions->add("done = ?", array(0));
702 FROM wcf".WCF_N
."_package_installation_queue
704 ORDER BY queueID ASC";
705 $statement = WCF
::getDB()->prepareStatement($sql);
706 $statement->execute($conditions->getParameters());
707 $packageInstallation = $statement->fetchArray();
709 if (!isset($packageInstallation['queueID'])) {
710 $url = LinkHandler
::getInstance()->getLink('PackageList');
711 HeaderUtil
::redirect($url);
715 $url = LinkHandler
::getInstance()->getLink('Package', array(), 'action='.$packageInstallation['action'].'&queueID='.$packageInstallation['queueID']);
716 HeaderUtil
::redirect($url);
722 * Displays last confirmation before plugin installation.
724 public function beginInstallation() {
726 $requirements = $this->getArchive()->getRequirements();
727 $openRequirements = $this->getArchive()->getOpenRequirements();
729 $updatableInstances = array();
730 $missingPackages = 0;
731 foreach ($requirements as $key => $requirement) {
732 if (isset($openRequirements[$requirement['name']])) {
733 $requirements[$key]['status'] = 'missing';
734 $requirements[$key]['action'] = $openRequirements[$requirement['name']]['action'];
736 if (!isset($requirements[$key]['file'])) {
737 if ($openRequirements[$requirement['name']]['action'] === 'update') {
738 $requirements[$key]['status'] = 'missingVersion';
739 $requirements[$key]['existingVersion'] = $openRequirements[$requirement['name']]['existingVersion'];
744 $requirements[$key]['status'] = 'delivered';
748 $requirements[$key]['status'] = 'installed';
752 // get other instances
753 if ($this->action
== 'install') {
754 $updatableInstances = $this->getArchive()->getUpdatableInstances();
757 ACPMenu
::getInstance()->setActiveMenuItem('wcf.acp.menu.link.package.install');
758 WCF
::getTPL()->assign(array(
759 'archive' => $this->getArchive(),
760 'requiredPackages' => $requirements,
761 'missingPackages' => $missingPackages,
762 'updatableInstances' => $updatableInstances,
763 'excludingPackages' => $this->getArchive()->getConflictedExcludingPackages(),
764 'excludedPackages' => $this->getArchive()->getConflictedExcludedPackages(),
765 'queueID' => $this->queue
->queueID
767 WCF
::getTPL()->display('packageInstallationConfirm');
772 * Checks the package installation queue for outstanding entries.
776 public static function checkPackageInstallationQueue() {
777 $sql = "SELECT queueID
778 FROM wcf".WCF_N
."_package_installation_queue
780 AND parentQueueID = 0
782 ORDER BY queueID ASC";
783 $statement = WCF
::getDB()->prepareStatement($sql);
784 $statement->execute(array(WCF
::getUser()->userID
));
785 $row = $statement->fetchArray();
791 return $row['queueID'];
795 * Executes post-setup actions.
797 public function completeSetup() {
798 // rebuild dependencies
799 Package
::rebuildPackageDependencies($this->queue
->packageID
);
801 // mark queue as done
802 $queueEditor = new PackageInstallationQueueEditor($this->queue
);
803 $queueEditor->update(array(
808 $this->nodeBuilder
->purgeNodes();
810 // update package version
811 if ($this->action
== 'update') {
812 $packageEditor = new PackageEditor($this->getPackage());
813 $packageEditor->update(array(
814 'updateDate' => TIME_NOW
,
815 'packageVersion' => $this->archive
->getPackageInfo('version')
819 // clear language files once whole installation is completed
820 LanguageEditor
::deleteLanguageFiles();
823 CacheHandler
::getInstance()->clear(WCF_DIR
.'cache/', '*');
827 * Updates queue information.
829 public function updatePackage() {
830 if (empty($this->queue
->packageName
)) {
831 $queueEditor = new PackageInstallationQueueEditor($this->queue
);
832 $queueEditor->update(array(
833 'packageName' => $this->getArchive()->getLocalizedPackageInfo('packageName')
837 $this->queue
= new PackageInstallationQueue($this->queue
->queueID
);
842 * Validates specific php requirements.
844 * @param array $requirements
845 * @return array<array>
847 public static function validatePHPRequirements(array $requirements) {
850 // validate php version
851 if (isset($requirements['version'])) {
853 if (version_compare(PHP_VERSION
, $requirements['version'], '>=')) {
858 $errors['version'] = array(
859 'required' => $requirements['version'],
860 'installed' => PHP_VERSION
865 // validate extensions
866 if (isset($requirements['extensions'])) {
867 foreach ($requirements['extensions'] as $extension) {
868 $passed = (extension_loaded($extension)) ?
true : false;
871 $errors['extension'][] = array(
872 'extension' => $extension
879 if (isset($requirements['settings'])) {
880 foreach ($requirements['settings'] as $setting => $value) {
881 $iniValue = ini_get($setting);
883 $passed = self
::compareSetting($setting, $value, $iniValue);
885 $errors['setting'][] = array(
886 'setting' => $setting,
887 'required' => $value,
888 'installed' => ($iniValue === false) ?
'(unknown)' : $iniValue
894 // validate functions
895 if (isset($requirements['functions'])) {
896 foreach ($requirements['functions'] as $function) {
897 $function = StringUtil
::toLowerCase($function);
899 $passed = self
::functionExists($function);
901 $errors['function'][] = array(
902 'function' => $function
909 if (isset($requirements['classes'])) {
910 foreach ($requirements['classes'] as $class) {
913 // see: http://de.php.net/manual/en/language.oop5.basic.php
914 if (preg_match('~[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.~', $class)) {
915 $globalClass = '\\'.$class;
917 if (class_exists($globalClass, false)) {
923 $errors['class'][] = array(
935 * Validates if an function exists and is not blacklisted by suhosin extension.
937 * @param string $function
939 * @see http://de.php.net/manual/en/function.function-exists.php#77980
941 protected static function functionExists($function) {
942 if (extension_loaded('suhosin')) {
943 $blacklist = @ini_get
('suhosin.executor.func.blacklist');
944 if (!empty($blacklist)) {
945 $blacklist = explode(',', $blacklist);
946 foreach ($blacklist as $disabledFunction) {
947 $disabledFunction = StringUtil
::toLowerCase(StringUtil
::trim($disabledFunction));
949 if ($function == $disabledFunction) {
956 return function_exists($function);
960 * Compares settings, converting values into compareable ones.
962 * @param string $setting
963 * @param string $value
964 * @param mixed $compareValue
967 protected static function compareSetting($setting, $value, $compareValue) {
968 if ($compareValue === false) return false;
970 $value = StringUtil
::toLowerCase($value);
971 $trueValues = array('1', 'on', 'true');
972 $falseValues = array('0', 'off', 'false');
974 // handle values considered as 'true'
975 if (in_array($value, $trueValues)) {
976 return ($compareValue) ?
true : false;
978 // handle values considered as 'false'
979 else if (in_array($value, $falseValues)) {
980 return (!$compareValue) ?
true : false;
982 else if (!is_numeric($value)) {
983 $compareValue = self
::convertShorthandByteValue($compareValue);
984 $value = self
::convertShorthandByteValue($value);
987 return ($compareValue >= $value) ?
true : false;
991 * Converts shorthand byte values into an integer representing bytes.
993 * @param string $value
995 * @see http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
997 protected static function convertShorthandByteValue($value) {
998 // convert into bytes
999 $lastCharacter = StringUtil
::substring($value, -1);
1000 switch ($lastCharacter) {
1003 return (int)$value * 1073741824;
1008 return (int)$value * 1048576;
1013 return (int)$value * 1024;