AppserverIo\Appserver\Meta\Composer\Script\Setup::prepareProperties PHP Method

prepareProperties() public static method

Merge the properties based on the passed OS.
public static prepareProperties ( string $os, array $contextProperties ) : void
$os string The OS we want to merge the properties for
$contextProperties array The properties to merge
return void
    public static function prepareProperties($os, array $contextProperties)
    {
        // merge all properties
        Setup::$mergedProperties = array_merge($contextProperties, Setup::$defaultProperties, Setup::$osProperties[$os]);
        // prepare the properties for the OS identifier, e. g. iron-horse_debian_x86_64
        Setup::$mergedProperties[SetupKeys::OS_IDENTIFIER] = sprintf('%s_%s_%s', str_replace(' ', '-', strtolower(Setup::$mergedProperties[SetupKeys::RELEASE_NAME])), $os, Setup::$mergedProperties[SetupKeys::OS_ARCHITECTURE]);
        // prepare the properties for the software identifier, e. g. appserver/1.0.0 (debian) PHP/5.5.21
        Setup::$mergedProperties[SetupKeys::SOFTWARE_IDENTIFIER] = sprintf('appserver/%s (%s) PHP/%s', Setup::$mergedProperties[SetupKeys::VERSION], Setup::$mergedProperties[SetupKeys::OS_FAMILY], Setup::$mergedProperties[SetupKeys::PHP_VERSION]);
    }

Usage Example

Example #1
0
 /**
  * Prepares the context by given event or without event for other usage
  *
  * @param null|string $installDir The install dir to check for info files
  * @param null|Event  $event      The event instance or null
  *
  * @return void
  */
 public static function prepareContext($installDir = null, $event = null)
 {
     // initialize the installation directory
     if (is_null($installDir)) {
         $installDir = getcwd();
     }
     // check if we've a file with the actual version number
     $version = '';
     if (file_exists($filename = $installDir . '/etc/appserver/.release-version')) {
         $version = file_get_contents($filename);
     } else {
         // load the version (GIT) of this package as fallback if called with event instance
         if (!is_null($event)) {
             $version = $event->getComposer()->getPackage()->getPrettyVersion();
         }
     }
     // check if we've a file with the actual release name
     if (file_exists($filename = $installDir . '/etc/appserver/.release-name')) {
         $releaseName = file_get_contents($filename);
     } else {
         // set the release name to 'Unknown' if not
         $releaseName = 'Unknown';
     }
     // prepare the context properties
     $contextProperties = array(SetupKeys::VERSION => $version, SetupKeys::INSTALL_DIR => $installDir, SetupKeys::RELEASE_NAME => $releaseName);
     // load the OS signature => sscanf is necessary to detect Windows, e. g. Windows NT for Windows 7
     list($os, ) = sscanf(strtolower(php_uname('s')), '%s %s');
     // check what OS we are running on
     switch ($os) {
         // installation running on Linux
         case SetupKeys::OS_FAMILY_LINUX:
             // get the distribution
             $distribution = Setup::getLinuxDistro();
             // if we cant find one of the supported systems
             if ($distribution == null) {
                 // set debian as default
                 $distribution = SetupKeys::OS_DEBIAN;
                 // write a message to the console if called with event instance
                 if (!is_null($event)) {
                     $event->getIo()->write(sprintf('<warning>Unknown Linux distribution found, use Debian default values: ' . 'Please check user/group configuration in etc/appserver/appserver.xml</warning>'));
                 }
             }
             // merge the properties for the found Linux distribution
             Setup::prepareProperties($distribution, $contextProperties);
             break;
             // installation running on Mac OS X
         // installation running on Mac OS X
         case SetupKeys::OS_FAMILY_DARWIN:
             // merge the properties for Mac OS X
             Setup::prepareProperties($os, $contextProperties);
             break;
             // installation running on Windows
         // installation running on Windows
         case SetupKeys::OS_FAMILY_WINDOWS:
             // merge the properties for Windows
             Setup::prepareProperties($os, $contextProperties);
             break;
             // all other OS are NOT supported actually
         // all other OS are NOT supported actually
         default:
             break;
     }
 }