private function runCommand($cmd, $package = null, $args, $noAddtlArguments = false)
    {
        $translator = $this->getServiceLocator()->get('translator');
        $docPath = str_replace(['\\', 'public/../'], '', $this->getDocumentRoot());
        $docPath = trim(substr($docPath, 0, strlen($docPath) - 1)); // remove last "/" trail


        set_time_limit(0);
        ini_set('memory_limit', -1);
        putenv('COMPOSER_HOME=' . self::COMPOSER);


        if (in_array($cmd, $this->availableCommands())) {

            $dryRunArgs = null;

            if ($this->getDryRun()) {
                $dryRunArgs = self::DRY_RUN_ARGS;
            }

            $noProgress = self::NO_PROGRESS;
            $ignoreReqs = self::IGNORE_REQ;
            $preferDist = self::PREFER_DIST;
            $noScript = self::NO_SCRIPTS;
            $commandString = "$cmd $package $dryRunArgs $args $ignoreReqs $noProgress $noScript $preferDist --working-dir=\"$docPath\"";

            // override commandstring if noAddtlArguments is set to "true"
            if ($noAddtlArguments) {
                $commandString = "$cmd --working-dir=\"$docPath\"";
            }

            $input = new StringInput($commandString);
            $output = new StreamOutput(fopen('php://output', 'w'));
            $composer = new Application();
            $formatter = $output->getFormatter();

            $formatter->setDecorated(true);
            $formatter->setStyle('error', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::ERROR));
            $formatter->setStyle('info', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::INFO));
            $formatter->setStyle('comment', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::COMMENT));
            $formatter->setStyle('warning', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::ERROR));
            $output->setFormatter($formatter);

            chdir($docPath);

            if (PHP_OS !== 'AIX' && DIRECTORY_SEPARATOR == '/') {
                /** proc_open(): fork failed - Cannot allocate memory [fix] | linux only */
                shell_exec('sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024');
                shell_exec('sudo /sbin/mkswap /var/swap.1');
                shell_exec('sudo /sbin/swapon /var/swap.1');
            }

            $composer->run($input, $output);

            return $output;
        }

        return sprintf($translator->translate('tr_market_place_unknown_command'), $cmd);
    }
private function runCommand($cmd, $package = null, $args, $noAddtlArguments = false)
    {
        $translator = $this->getServiceLocator()->get('translator');
        $docPath = str_replace(['\\', 'public/../'], '', $this->getDocumentRoot());
        $docPath = trim(substr($docPath, 0, strlen($docPath) - 1)); // remove last "/" trail


        set_time_limit(0);
        ini_set('memory_limit', -1);
        putenv('COMPOSER_HOME=' . self::COMPOSER);


        if (in_array($cmd, $this->availableCommands())) {

            $dryRunArgs = null;

            if ($this->getDryRun()) {
                $dryRunArgs = self::DRY_RUN_ARGS;
            }

            $noProgress = self::NO_PROGRESS;
            $ignoreReqs = self::IGNORE_REQ;
            $preferDist = self::PREFER_DIST;
            $noScript = self::NO_SCRIPTS;
            $commandString = "$cmd $package $dryRunArgs $args $ignoreReqs $noProgress $noScript $preferDist --working-dir=\"$docPath\"";

            // override commandstring if noAddtlArguments is set to "true"
            if ($noAddtlArguments) {
                $commandString = "$cmd --working-dir=\"$docPath\"";
            }

            $input = new StringInput($commandString);
            $output = new StreamOutput(fopen('php://output', 'w'));
            $composer = new Application();
            $formatter = $output->getFormatter();

            $formatter->setDecorated(true);
            $formatter->setStyle('error', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::ERROR));
            $formatter->setStyle('info', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::INFO));
            $formatter->setStyle('comment', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::COMMENT));
            $formatter->setStyle('warning', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::ERROR));
            $output->setFormatter($formatter);

            chdir($docPath);

            if (PHP_OS !== 'AIX' && DIRECTORY_SEPARATOR == '/') {
                /** proc_open(): fork failed - Cannot allocate memory [fix] | linux only */
                shell_exec('sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024');
                shell_exec('sudo /sbin/mkswap /var/swap.1');
                shell_exec('sudo /sbin/swapon /var/swap.1');
            }

            $composer->run($input, $output);

            return $output;
        }

        return sprintf($translator->translate('tr_market_place_unknown_command'), $cmd);
    }
private function runCommand ( $ cmd , $ package = null , $ args , $ noAddtlArguments = false ) { $ translator = $ this -> getServiceLocator ( ) -> get ( 'translator' ) ; $ docPath = str_replace ( [ '\\' , 'public/../' ] , '' , $ this -> getDocumentRoot ( ) ) ; $ docPath = trim ( substr ( $ docPath , 0 , strlen ( $ docPath ) - 1 ) ) ; // remove last "/" trail set_time_limit ( 0 ) ; ini_set ( 'memory_limit' , - 1 ) ; putenv ( 'COMPOSER_HOME=' . self :: COMPOSER ) ; if ( in_array ( $ cmd , $ this -> availableCommands ( ) ) ) { $ dryRunArgs = null ; if ( $ this -> getDryRun ( ) ) { $ dryRunArgs = self :: DRY_RUN_ARGS ; } $ noProgress = self :: NO_PROGRESS ; $ ignoreReqs = self :: IGNORE_REQ ; $ preferDist = self :: PREFER_DIST ; $ noScript = self :: NO_SCRIPTS ; $ commandString = "$cmd $package $dryRunArgs $args $ignoreReqs $noProgress $noScript $preferDist --working-dir=\"$docPath\"" ; // override commandstring if noAddtlArguments is set to "true" if ( $ noAddtlArguments ) { $ commandString = "$cmd --working-dir=\"$docPath\"" ; } $ input = new StringInput ( $ commandString ) ; $ output = new StreamOutput ( fopen ( 'php://output' , 'w' ) ) ; $ composer = new Application ( ) ; $ formatter = $ output -> getFormatter ( ) ; $ formatter -> setDecorated ( true ) ; $ formatter -> setStyle ( 'error' , new ComposerOutputFormatterStyle ( ComposerOutputFormatterStyle :: ERROR ) ) ; $ formatter -> setStyle ( 'info' , new ComposerOutputFormatterStyle ( ComposerOutputFormatterStyle :: INFO ) ) ; $ formatter -> setStyle ( 'comment' , new ComposerOutputFormatterStyle ( ComposerOutputFormatterStyle :: COMMENT ) ) ; $ formatter -> setStyle ( 'warning' , new ComposerOutputFormatterStyle ( ComposerOutputFormatterStyle :: ERROR ) ) ; $ output -> setFormatter ( $ formatter ) ; chdir ( $ docPath ) ; if ( PHP_OS !== 'AIX' && DIRECTORY_SEPARATOR == '/' ) { /** proc_open(): fork failed - Cannot allocate memory [fix] | linux only */ shell_exec ( 'sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024' ) ; shell_exec ( 'sudo /sbin/mkswap /var/swap.1' ) ; shell_exec ( 'sudo /sbin/swapon /var/swap.1' ) ; } $ composer -> run ( $ input , $ output ) ; return $ output ; } return sprintf ( $ translator -> translate ( 'tr_market_place_unknown_command' ) , $ cmd ) ; }
This calls the composer CLI to execute a command

@param $cmd
@param null $package
@param $args
@param bool $noAddtlArguments

@return string|\Symfony\Component\Console\Output\StreamOutput
@throws \Exception
This calls the composer CLI to execute a command