AppserverIo\Appserver\Meta\Composer\Script\Setup::prepareContext PHP Метод

prepareContext() публичный статический Метод

Prepares the context by given event or without event for other usage
public static prepareContext ( null | string $installDir = null, null | Composer\Script\Event $event = null ) : void
$installDir null | string The install dir to check for info files
$event null | Composer\Script\Event The event instance or null
Результат 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;
        }
    }

Usage Example

Пример #1
0
 /**
  * This method will be invoked by composer after a successful installation and creates
  * the application server configuration file under etc/appserver/appserver.xml.
  *
  * @param \Composer\Script\Event $event The event that invokes this method
  *
  * @return void
  */
 public static function postInstall(Event $event)
 {
     // initialize the installation directory
     $override = false;
     $installDir = getcwd();
     // check the arguments for an installation directory
     foreach ($event->getArguments() as $arg) {
         // extract arguments
         list($key, ) = explode('=', $arg);
         // query we want to override files
         if ($key === SetupKeys::ARG_OVERRIDE) {
             $override = true;
         }
         // query for a custom installation directory
         if ($key === SetupKeys::ARG_INSTALL_DIR) {
             $installDir = str_replace("{$key}=", '', $arg);
         }
     }
     Setup::prepareContext($installDir, $event);
     // process and move the configuration files their target directory
     Setup::processTemplate('etc/appserver/appserver.xml', $override);
     // write a message to the console
     $event->getIo()->write(sprintf('%s<info>Successfully invoked appserver.io Composer post-install-cmd script ...</info>', Setup::$logo));
 }
All Usage Examples Of AppserverIo\Appserver\Meta\Composer\Script\Setup::prepareContext