Execute command

@return self Returns itself

@throws Exception on error
973497
public function execute() {
        if (count($this->config['arguments']) === 1) {
            if (array_key_exists($this->config['arguments'][0], $this->config['commands'])) {
                // APP help COMMAND:
                $class = $this->config['commands'][$this->config['arguments'][0]]['class'];

                if (!class_exists($class) ||
                    !is_subclass_of($class, __NAMESPACE__ . '\\Executes')
                ) {
                    throw new RuntimeException(sprintf(
                        'Command "%s" not found',
                        $this->config['arguments'][0]
                    ), ExitApp::BAD_USER_INTERACTION);
                }

                /** @var Executes $command */
                $command = new $class($this->config, $this->log);
                $command->printUsage();
            } else {
                // APP help unknown:
                throw new RuntimeException(sprintf(
                    'Command "%s" not found',
                    $this->config['arguments'][0]
                ), ExitApp::BAD_USER_INTERACTION);
            }
        } else {
            // APP help:
            $this->printUsage();
        }

        return $this;
    }
497254
public function execute()
    {
        $command = $this->getExecCommand();

        if (!$command) {
            return false;
        }

        if ($this->useExec) {
            $execCommand = $this->captureStdErr ? "$command 2>&1" : $command;
            exec($execCommand, $output, $this->_exitCode);
            $this->_stdOut = implode("\n", $output);
            if ($this->_exitCode!==0) {
                $this->_stdErr = $this->_stdOut;
                $this->_error = empty($this->_stdErr) ? 'Command failed' : $this->_stdErr;
                return false;
            }
        } else {
            $descriptors = array(
                1   => array('pipe','w'),
                2   => array('pipe', $this->getIsWindows() ? 'a' : 'w'),
            );
            if ($this->_stdIn!==null) {
                $descriptors[0] = array('pipe', 'r');
            }

            $process = proc_open($command, $descriptors, $pipes, $this->procCwd, $this->procEnv, $this->procOptions);

            if (is_resource($process)) {

                if ($this->_stdIn!==null) {
                    if (is_resource($this->_stdIn) &&
                        in_array(get_resource_type($this->_stdIn), array('file', 'stream'), true)) {
                        stream_copy_to_stream($this->_stdIn, $pipes[0]);
                    } else {
                        fwrite($pipes[0], $this->_stdIn);
                    }
                    fclose($pipes[0]);
                }
                $this->_stdOut = stream_get_contents($pipes[1]);
                $this->_stdErr = stream_get_contents($pipes[2]);
                fclose($pipes[1]);
                fclose($pipes[2]);

                $this->_exitCode = proc_close($process);

                if ($this->_exitCode!==0) {
                    $this->_error = $this->_stdErr ? $this->_stdErr : "Failed without error message: $command";
                    return false;
                }
            } else {
                $this->_error = "Could not run command $command";
                return false;
            }
        }

        $this->_executed = true;

        return true;
    }
700548
public function command(): self
    {
        $parameters = func_get_args();
        $command = strtoupper(array_shift($parameters));
        $parameters = array_map([$this, 'parameter'], $parameters);

        $this->zpl[] = '^' . $command . implode(',', $parameters);

        return $this;
    }
1117489
public function run() {
        // Use the global $argv variable to retrieve command-line arguments
        global $argv;
        
        // index[0] is the script name and index[1] is the command name
        if (isset($argv[1])) {
            // Get the command through map
            $commandName = strtolower($argv[1]);

            if (isset($this->_commands[$commandName])) {
                $cmd = $this->_commands[$commandName];

                // Execute the command
                return call_user_func($cmd, $this->_input, $this->_output);
            } else {
                // Command not found
                exit('Command not found: "' . $commandName . '"' . PHP_EOL);
            }
        }

        // Call the default command if set
        if (!is_null($this->_default) && is_callable($this->_default)) {
            return call_user_func($this->_default, $this->_input, $this->_output);
        }
    }
89174
public static function getCommand(): Command
    {
        if (is_null(self::$exec)) {
            self::$exec = new Command();
        }
        return self::$exec;
    }
973513
public function execute() {
		// if source is not specified
		if(!$this->Source) {
			// add an error
			$this->Error = 'No source image provided';	
			// return false already
			return(false);
		}
		// check if the source file exists
		if(!file_exists($this->Source)) {
			// add an error
			$this->Error = 'Source image does not exist';	
			// return false already
			return(false);
		}
		// if no destination
		if(!$this->Destination) {
			// add an error
			$this->Error = 'No destination provided';	
			// return false already
			return(false);
		}
		// if the destination is not a folder and already exists
		if(!is_dir($this->Destination) && file_exists($this->Destination)) {
			// throw an exception
			$this->Error = 'Destination image already exists';	
			// return false
			return(false);
		}
		// if the destination is not a directory
		elseif(!is_dir($this->Destination)) {
			// try to explode by slash to find the file name
			$exploded = explode('/',$this->Destination);
			// get the last element wich is the file name
			$this->Name = $exploded[count($exploded)-1];
			// set the directory as being the path minus the name
			$this->Destination = str_replace($this->Name,'',$this->Destination);
		}
		// the destination if a folder without name
		elseif(is_dir($this->Destination)) {
			// if the trailing slash is ommited
			if(substr($this->Destination,-1) != '/') {
				// add it to the path
				$this->Destination .= '/';	
			}
			// generate a name being sha1(file) +sha1(microtime)
			$this->Name = sha1_file($this->Source);
		}
		// destination unknown !
		else {
			// add an error
			$this->Error = 'Destination is unkown or incorrect';
			// return an error
			return(false);
		}
		// check if the destination is writable
		if(!is_writable($this->Destination)) {
			// add an error
			$this->Error = 'Destination is not writable';
			// return an error
			return(false);
		}
		// compute filesize
		$this->Size = filesize($this->Source);
		// get the type of the source image
		$this->Type = Filesystem::type($this->Source, true);
		// if failed to get a type
		if(!$this->Type) {
			// add an error
			$this->Error = 'Failed to get mimetype';
			// return an error
			return(false);		
		}
		// if the source type is not allowed
		if(!in_array($this->Type, $this->Allowed)) {
			// add an error
			$this->Error = 'This image is not in the list of allowed formats : ' . implode(',',$this->Allowed);
			// return an error
			return(false);
		}
		// if we have a png
		if($this->Type == 'image/png') {
			// create image
			$this->Image = imagecreatefrompng($this->Source);
		}
		// if we have a jpg
		elseif($this->Type == 'image/jpeg') {
			// create image
			$this->Image = imagecreatefromjpeg($this->Source);
		}		// get the width
		$this->OriginalWidth = imageSX($this->Image);
		// get the height
		$this->OriginalHeight = imageSY($this->Image);
		// if the picture is horizontal
		if($this->OriginalHeight < $this->OriginalWidth) {
			// set the height
			$this->Height 	= round($this->Maximum * $this->OriginalHeight / $this->OriginalWidth , 0);
			// set the width
			$this->Width 	= $this->Maximum;
		}
		// else the picture is vertical or cubic
		else {
			// set the width
			$this->Width = round($this->Maximum * $this->OriginalWidth / $this->OriginalHeight , 0);
			// set the height
			$this->Height = $this->Maximum;
		}
		// create a canvas for the resized image
		$this->Sized = ImageCreateTrueColor($this->Width,$this->Height);
		// resize and inject into the canvas
		imagecopyresampled(
			$this->Sized, $this->Image,
			0, 0, 0, 0,
			$this->Width, $this->Height,
			$this->OriginalWidth, $this->OriginalHeight
		);
		// destroy the source handler
		imagedestroy($this->Image);
		// if output is png
		if($this->Output == 'image/png') {
			// roof
			$this->Quality = $this->Quality > 90 ? '90' : $this->Quality;
			// convert the jpeg quality index to a png quality index
			$this->Quality = round(abs(-0.1 * $this->Quality + 10));
			// create png image
			$status = imagepng($this->Sized,$this->Destination.$this->Name,$this->Quality);
		}
		elseif($this->Output == 'image/jpeg') {
			// create jpeg image
			$status = imagejpeg($this->Sized,$this->Destination.$this->Name,$this->Quality);
		}
		// destroy the sized handler
		imagedestroy($this->Sized);
		
		// if everything went well
		if($status) {
			// get the size of the generated thumbnail
			$this->Size = filesize($this->Destination . $this->Name);
			// creation succeeded
			return(true);
		}
		// failed somewhere
		else {
			// add an error
			$this->Error = 'Failed to write thumbnail to the disk';
			// and return false
			return(false);	
		}
	}
158802
public function executeCommand()
    {
        $this->adapter->setCommandArray($this->commandArray);
        $result = $this->adapter->execute();
        $commandArrayUsed = $this->adapter->getCommandArray();
        $this->clearCommandArray();
        $this->checkResultForError($result, $commandArrayUsed);
        return $result;
    }
922510
public function run() {
        try {
            $this->command->execute($this->console, $this->parser->getArguments());
        } catch (\Exception $e) {
            $this->writeException($e);
            if ($this->exitOnException) {
                exit($e->getCode() ? : 1);
            }
            throw $e;
        }
    }
586495
public function execute()
	{
		$query  = $this->factory->builder($this->insert)->process();
		$result = $this->pdo->query($query);
		if(!$result)
		{
			throw new \Exception('An error is while the insertion occurred! (query: "' . $query . '")');
		}

		return $this->pdo->lastInsertId();
	}
267303
public function execute(Command $command)
    {
        if (!$this->innerCommandBus) {
            throw new Exception('No inner bus defined for this decorator. Set an inner bus with setInnerBus()');
        }

        $response = $this->innerCommandBus->execute($command);

        $eventName = $this->getEventName($command);

        $this->dispatcher->dispatch($eventName, [$command]);

        return $response;
    }
1028762
public function exec() {
		$this->ch = curl_init();
		curl_setopt_array($this->ch, [
			CURLOPT_URL => $this->url,
			CURLOPT_POSTFIELDS => $this->data,
			CURLOPT_CUSTOMREQUEST => $this->requestType,
			CURLOPT_HTTPHEADER => $this->createHeaders(),
			CURLOPT_TIMEOUT_MS => intval($this->timeout * 1000),
			CURLOPT_ENCODING => 'gzip',
			CURLOPT_FAILONERROR => false,
			CURLOPT_HEADER => true,
			CURLOPT_RETURNTRANSFER => true,
		]);
		curl_setopt_array($this->ch, $this->extraOpts);

		if ($this->username && $this->password) {
			curl_setopt($this->ch, CURLOPT_USERPWD, "{$this->username}:{$this->password}");
		}

		if ($this->data !== null)
			curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->data);

		$this->beforeExec();

		$resultData = curl_exec($this->ch);
		$httpCode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

		if (curl_errno($this->ch) !== CURLE_OK) {
			throw new Exception(curl_error($this->ch), curl_errno($this->ch));
		}

		$response = new Response($httpCode, $resultData, curl_getinfo($this->ch, CURLINFO_HEADER_SIZE));

		if  ($httpCode >= 400) {
			throw new Exception("HTTP transfer error {$httpCode}", null, $httpCode, $response);
		}

		curl_close($this->ch);

		return $response;
	}
514842
public function execute()
	{
		if (count($this->children) && count($this->input->args))
		{
			$name = $this->input->args[0];

			try
			{
				return $this->executeSubCommand($name);
			}
			catch (CommandNotFoundException $e)
			{
				$e->getCommand()->renderAlternatives($e->getChild(), $e);

				return $e->getCode();
			}
			catch (\Exception $e)
			{
				$this->renderException($e);

				return $e->getCode();
			}
		}

		if ($this->handler)
		{
			if ($this->handler instanceof \Closure)
			{
				$code = $this->handler;

				return $code($this);
			}
			elseif (is_callable($this->handler))
			{
				return call_user_func($this->handler, $this);
			}
		}

		return $this->doExecute();
	}
530107
static function executeCommand($command)
    {
        exec($command, $output, $resultCode);

        if ($resultCode > 0) {
            $output = implode("\n", $output);
            throw new Exception("Failed to execute command: '$command' with output: '$output' ");
        }
    }
141220
public function execute()
    {
        $this->_setOptions();

        $response = $this->_execute();
        $this->_saveStatusCode();

        $curlErrorNumber = $this->_getErrorNumber();

        $this->_close();

        if ($curlErrorNumber) {
            /**
             * @var \OxidEsales\Eshop\Core\Exception\StandardException $exception
             */
            $exception = oxNew(\OxidEsales\Eshop\Core\Exception\StandardException::class);
            $lang = \OxidEsales\Eshop\Core\Registry::getLang();
            $exception->setMessage(sprintf($lang->translateString('EXCEPTION_CURL_ERROR', $lang->getTplLanguage()), $curlErrorNumber));
            throw $exception;
        }

        return $response;
    }
807766
private function exec()
    {
        $return_data = '';
        ob_start();
        try {
            $return_data = call_user_func_array($this->command, $this->args);
            $this->successful = true;
        } catch (\RuntimeException $e) {
            $this->successful = false;
        }
        $this->output = ob_get_clean() . (is_string($return_data) ? $return_data : '');

        $this->postRun();
    }
1355801
public function execute()
    {
        parent::execute();

        $client = ServicesContainer::instance()->getClient();
        return $client->processReport($this);
    }
1177259
public function perform()
    {
        $app = $this->application();

        $command = $this->getConsoleCommand($app);

        $inputDefinition = $this->getInputDefinition($this->args);

        // Create Input object with $this->args loaded as Input arguments
        $input  = new ArrayInput($this->args, $inputDefinition);
        $output = new ConsoleOutput;

        // Output error details to the console if available
        try {
            $command->run($input, $output);
        } catch (\Exception $e) {
            $output->writeln('Exception: '.$e->getMessage());
            $output->writeln('Code: '.$e->getCode());
            $output->writeln('Stack trace: '.$e->getTraceAsString());

            throw $e;
        }
    }