public function matchCommand(string $path): Command
    {
        // If the path matches a set command path
        if (isset(self::$commands[$path])) {
            return self::$commands[$path];
        }

        $command = null;

        // Otherwise iterate through the commands and attempt to match via regex
        foreach (self::$paths as $regex => $commandPath) {
            // If the preg match is successful, we've found our command!
            if (preg_match($regex, $path, $matches)) {
                // Check if this command is provided
                if ($this->isProvided($commandPath)) {
                    // Initialize the provided command
                    $this->initializeProvided($commandPath);
                }

                // Clone the command to avoid changing the one set in the master
                // array
                $command = clone self::$commands[$commandPath];
                // The first match is the path itself
                unset($matches[0]);

                // Set the matches
                $command->setMatches($matches);

                return $command;
            }
        }

        // If a command was not found
        if (null === $command) {
            // Throw a not found exception
            throw new CommandNotFound('The command ' . $path . ' not found.');
        }

        return $command;
    }
public function matchCommand(string $path): Command
    {
        // If the path matches a set command path
        if (isset(self::$commands[$path])) {
            return self::$commands[$path];
        }

        $command = null;

        // Otherwise iterate through the commands and attempt to match via regex
        foreach (self::$paths as $regex => $commandPath) {
            // If the preg match is successful, we've found our command!
            if (preg_match($regex, $path, $matches)) {
                // Check if this command is provided
                if ($this->isProvided($commandPath)) {
                    // Initialize the provided command
                    $this->initializeProvided($commandPath);
                }

                // Clone the command to avoid changing the one set in the master
                // array
                $command = clone self::$commands[$commandPath];
                // The first match is the path itself
                unset($matches[0]);

                // Set the matches
                $command->setMatches($matches);

                return $command;
            }
        }

        // If a command was not found
        if (null === $command) {
            // Throw a not found exception
            throw new CommandNotFound('The command ' . $path . ' not found.');
        }

        return $command;
    }
public function matchCommand ( string $ path ) : Command { // If the path matches a set command path if ( isset ( self :: $ commands [ $ path ] ) ) { return self :: $ commands [ $ path ] ; } $ command = null ; // Otherwise iterate through the commands and attempt to match via regex foreach ( self :: $ paths as $ regex => $ commandPath ) { // If the preg match is successful, we've found our command! if ( preg_match ( $ regex , $ path , $ matches ) ) { // Check if this command is provided if ( $ this -> isProvided ( $ commandPath ) ) { // Initialize the provided command $ this -> initializeProvided ( $ commandPath ) ; } // Clone the command to avoid changing the one set in the master // array $ command = clone self :: $ commands [ $ commandPath ] ; // The first match is the path itself unset ( $ matches [ 0 ] ) ; // Set the matches $ command -> setMatches ( $ matches ) ; return $ command ; } } // If a command was not found if ( null === $ command ) { // Throw a not found exception throw new CommandNotFound ( 'The command ' . $ path . ' not found.' ) ; } return $ command ; }
Match a command by path.

@param string $path The path

@throws \Valkyrja\Console\Exceptions\CommandNotFound

@return \Valkyrja\Console\Command
Match a command by path .