idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
52,000
public function set ( $ string ) { $ this -> clear ( ) ; fwrite ( $ this -> stream , $ string ) ; rewind ( $ this -> stream ) ; }
Sets the string to read from .
52,001
public function append ( $ string ) { $ pos = ftell ( $ this -> stream ) ; fseek ( $ this -> stream , 0 , SEEK_END ) ; fwrite ( $ this -> stream , $ string ) ; fseek ( $ this -> stream , $ pos ) ; }
Appends a string to the stream .
52,002
public static function forCommandName ( $ name , $ code = 0 , Exception $ cause = null ) { return new static ( sprintf ( 'The command "%s" does not exist.' , $ name ) , $ code , $ cause ) ; }
Creates an exception for the given command name .
52,003
public function setMinNbColumns ( $ minNbColumns ) { $ this -> minNbColumns = $ minNbColumns ; $ this -> maxNbColumns = max ( $ this -> maxNbColumns , $ minNbColumns ) ; return $ this ; }
Sets the minimum number of columns in the grid .
52,004
public function setMaxNbColumns ( $ maxNbColumns ) { $ this -> minNbColumns = min ( $ this -> minNbColumns , $ maxNbColumns ) ; $ this -> maxNbColumns = $ maxNbColumns ; return $ this ; }
Sets the maximum number of columns in the grid .
52,005
public function addAlias ( $ alias ) { Assert :: string ( $ alias , 'The command alias must be a string. Got: %s' ) ; Assert :: notEmpty ( $ alias , 'The command alias must not be empty.' ) ; Assert :: regex ( $ alias , '~^[a-zA-Z0-9\-]+$~' , 'The command alias should contain letters, digits and hyphens only. Got: %s' ) ; $ this -> aliases [ ] = $ alias ; return $ this ; }
Adds an alias name .
52,006
public function setDescription ( $ description ) { if ( null !== $ description ) { Assert :: string ( $ description , 'The command description must be a string or null. Got: %s' ) ; Assert :: notEmpty ( $ description , 'The command description must not be empty.' ) ; } $ this -> description = $ description ; return $ this ; }
Sets the description of the command .
52,007
public function setProcessTitle ( $ processTitle ) { if ( null !== $ processTitle ) { Assert :: string ( $ processTitle , 'The command process title must be a string or null. Got: %s' ) ; Assert :: notEmpty ( $ processTitle , 'The command process title must not be empty.' ) ; } $ this -> processTitle = $ processTitle ; return $ this ; }
Sets the title of the command process .
52,008
public function beginSubCommand ( $ name ) { $ config = new SubCommandConfig ( $ name , $ this ) ; $ this -> subCommandConfigs [ ] = $ config ; return $ config ; }
Starts a configuration block for a sub - command .
52,009
public function beginOptionCommand ( $ name , $ shortName = null ) { $ config = new OptionCommandConfig ( $ name , $ shortName , $ this ) ; $ this -> subCommandConfigs [ ] = $ config ; return $ config ; }
Starts a configuration block for an option command .
52,010
public function addSubCommandConfig ( SubCommandConfig $ config ) { $ this -> subCommandConfigs [ ] = $ config ; $ config -> setParentConfig ( $ this ) ; return $ this ; }
Adds configuration for a sub - command .
52,011
public function getSubCommandConfig ( $ name ) { foreach ( $ this -> subCommandConfigs as $ commandConfig ) { if ( $ name === $ commandConfig -> getName ( ) ) { return $ commandConfig ; } } throw NoSuchCommandException :: forCommandName ( $ name ) ; }
Returns the sub - command configuration for a given name .
52,012
public function hasSubCommandConfig ( $ name ) { foreach ( $ this -> subCommandConfigs as $ commandConfig ) { if ( $ name === $ commandConfig -> getName ( ) ) { return true ; } } return false ; }
Returns whether the command has a sub - command with a given name .
52,013
public function setParentConfig ( CommandConfig $ parentConfig ) { $ this -> parentConfig = $ parentConfig ; if ( $ parentConfig -> getApplicationConfig ( ) ) { $ this -> setApplicationConfig ( $ parentConfig -> getApplicationConfig ( ) ) ; } }
Sets the parent command configuration .
52,014
private function createArgs ( ArgsFormat $ format , RawArgs $ rawArgs ) { $ args = new Args ( $ format , $ rawArgs ) ; foreach ( $ this -> arguments as $ name => $ value ) { if ( $ format -> hasArgument ( $ name ) ) { $ args -> setArgument ( $ name , $ value ) ; } } foreach ( $ this -> options as $ name => $ value ) { if ( $ format -> hasOption ( $ name ) ) { $ args -> setOption ( $ name , $ value ) ; } } return $ args ; }
Creates the arguments from the current class state .
52,015
public static function drawTopBorder ( IO $ io , BorderStyle $ style , array $ columnLengths , $ indentation = 0 ) { self :: drawBorder ( $ io , $ columnLengths , $ indentation , $ style -> getLineHTChar ( ) , $ style -> getCornerTLChar ( ) , $ style -> getCrossingTChar ( ) , $ style -> getCornerTRChar ( ) , $ style -> getStyle ( ) ) ; }
Draws a top border .
52,016
public static function drawMiddleBorder ( IO $ io , BorderStyle $ style , array $ columnLengths , $ indentation = 0 ) { self :: drawBorder ( $ io , $ columnLengths , $ indentation , $ style -> getLineHCChar ( ) , $ style -> getCrossingLChar ( ) , $ style -> getCrossingCChar ( ) , $ style -> getCrossingRChar ( ) , $ style -> getStyle ( ) ) ; }
Draws a middle border .
52,017
public static function drawBottomBorder ( IO $ io , BorderStyle $ style , array $ columnLengths , $ indentation = 0 ) { self :: drawBorder ( $ io , $ columnLengths , $ indentation , $ style -> getLineHBChar ( ) , $ style -> getCornerBLChar ( ) , $ style -> getCrossingBChar ( ) , $ style -> getCornerBRChar ( ) , $ style -> getStyle ( ) ) ; }
Draws a bottom border .
52,018
public static function drawRow ( IO $ io , BorderStyle $ style , array $ row , array $ columnLengths , array $ alignments , $ cellFormat , Style $ cellStyle = null , $ paddingChar , $ indentation = 0 ) { $ totalLines = 0 ; foreach ( $ row as $ col => $ cell ) { $ row [ $ col ] = explode ( "\n" , $ cell ) ; $ totalLines = max ( $ totalLines , count ( $ row [ $ col ] ) ) ; } $ nbColumns = count ( $ row ) ; $ borderVLChar = $ io -> format ( $ style -> getLineVLChar ( ) , $ style -> getStyle ( ) ) ; $ borderVCChar = $ io -> format ( $ style -> getLineVCChar ( ) , $ style -> getStyle ( ) ) ; $ borderVRChar = $ io -> format ( $ style -> getLineVRChar ( ) , $ style -> getStyle ( ) ) ; for ( $ i = 0 ; $ i < $ totalLines ; ++ $ i ) { $ line = str_repeat ( ' ' , $ indentation ) ; $ line .= $ borderVLChar ; foreach ( $ row as $ col => & $ remainingLines ) { $ cellLine = $ remainingLines ? array_shift ( $ remainingLines ) : '' ; $ totalPadLength = $ columnLengths [ $ col ] - StringUtil :: getLength ( $ cellLine , $ io ) ; $ paddingLeft = '' ; $ paddingRight = '' ; if ( $ totalPadLength > 0 ) { $ alignment = isset ( $ alignments [ $ col ] ) ? $ alignments [ $ col ] : Alignment :: LEFT ; switch ( $ alignment ) { case Alignment :: LEFT : $ paddingRight = str_repeat ( $ paddingChar , $ totalPadLength ) ; break ; case Alignment :: RIGHT : $ paddingLeft = str_repeat ( $ paddingChar , $ totalPadLength ) ; break ; case Alignment :: CENTER : $ leftPadLength = floor ( $ totalPadLength / 2 ) ; $ paddingLeft = str_repeat ( $ paddingChar , $ leftPadLength ) ; $ paddingRight = str_repeat ( $ paddingChar , $ totalPadLength - $ leftPadLength ) ; break ; } } $ line .= $ io -> format ( sprintf ( $ cellFormat , $ paddingLeft . $ cellLine . $ paddingRight ) , $ cellStyle ) ; $ line .= $ col < $ nbColumns - 1 ? $ borderVCChar : $ borderVRChar ; } $ io -> write ( rtrim ( $ line ) . "\n" ) ; } }
Draws a bordered row of cells .
52,019
public function readLine ( $ default = null , $ length = null ) { if ( ! $ this -> interactive ) { return $ default ; } return $ this -> stream -> readLine ( $ length ) ; }
Reads a line from the input stream .
52,020
public function parseTokens ( $ string ) { $ this -> string = $ string ; $ this -> cursor = 0 ; $ this -> current = isset ( $ this -> string [ 0 ] ) ? $ this -> string [ 0 ] : null ; $ this -> next = isset ( $ this -> string [ 1 ] ) ? $ this -> string [ 1 ] : null ; $ previousLocale = setlocale ( LC_CTYPE , 0 ) ; setlocale ( LC_CTYPE , 'C' ) ; $ tokens = $ this -> doParseTokens ( ) ; setlocale ( LC_CTYPE , $ previousLocale ) ; return $ tokens ; }
Parses the tokens from the given string .
52,021
private function next ( ) { if ( ! $ this -> valid ( ) ) { return ; } ++ $ this -> cursor ; $ this -> current = $ this -> next ; $ this -> next = isset ( $ this -> string [ $ this -> cursor + 1 ] ) ? $ this -> string [ $ this -> cursor + 1 ] : null ; }
Advances the cursor to the next position .
52,022
private function doParseTokens ( ) { $ tokens = array ( ) ; while ( $ this -> valid ( ) ) { while ( ctype_space ( $ this -> current ) ) { $ this -> next ( ) ; } if ( $ this -> valid ( ) ) { $ tokens [ ] = $ this -> parseToken ( ) ; } } return $ tokens ; }
Parses an array of tokens .
52,023
private function parseToken ( ) { $ token = '' ; while ( $ this -> valid ( ) ) { if ( ctype_space ( $ this -> current ) ) { $ this -> next ( ) ; break ; } if ( '\\' === $ this -> current ) { $ token .= $ this -> parseEscapeSequence ( ) ; } elseif ( "'" === $ this -> current || '"' === $ this -> current ) { $ token .= $ this -> parseQuotedString ( ) ; } else { $ token .= $ this -> current ; $ this -> next ( ) ; } } return $ token ; }
Parses a single token .
52,024
private function parseQuotedString ( ) { $ string = '' ; $ delimiter = $ this -> current ; $ this -> next ( ) ; while ( $ this -> valid ( ) ) { if ( $ delimiter === $ this -> current ) { $ this -> next ( ) ; break ; } if ( '\\' === $ this -> current ) { $ string .= $ this -> parseEscapeSequence ( ) ; } elseif ( '"' === $ this -> current ) { $ string .= '"' . $ this -> parseQuotedString ( ) . '"' ; } elseif ( "'" === $ this -> current ) { $ string .= "'" . $ this -> parseQuotedString ( ) . "'" ; } else { $ string .= $ this -> current ; $ this -> next ( ) ; } } return $ string ; }
Parses a quoted string .
52,025
private function parseEscapeSequence ( ) { $ sequence = "'" === $ this -> next || '"' === $ this -> next ? $ this -> next : '\\' . $ this -> next ; $ this -> next ( ) ; $ this -> next ( ) ; return $ sequence ; }
Parses an escape sequence started by a backslash .
52,026
public function setHeaderRow ( array $ row ) { if ( null === $ this -> nbColumns ) { $ this -> nbColumns = count ( $ row ) ; } elseif ( count ( $ row ) !== $ this -> nbColumns ) { throw new LogicException ( sprintf ( 'Expected the header row to contain %s cells, but got %s.' , $ this -> nbColumns , count ( $ row ) ) ) ; } $ this -> headerRow = array_values ( $ row ) ; return $ this ; }
Sets the header cells of the table .
52,027
public function setRow ( $ index , array $ row ) { if ( null === $ this -> nbColumns ) { $ this -> nbColumns = count ( $ row ) ; } elseif ( count ( $ row ) !== $ this -> nbColumns ) { throw new LogicException ( sprintf ( 'Expected the row to contain %s cells, but got %s.' , $ this -> nbColumns , count ( $ row ) ) ) ; } $ this -> rows [ $ index ] = array_values ( $ row ) ; return $ this ; }
Sets a specific row in the table .
52,028
public function render ( IO $ io , $ indentation = 0 ) { $ layout = new BlockLayout ( ) ; $ this -> renderHelp ( $ layout ) ; $ layout -> render ( $ io , $ indentation ) ; }
Renders the usage .
52,029
protected function renderArguments ( BlockLayout $ layout , array $ arguments ) { $ layout -> add ( new Paragraph ( '<b>ARGUMENTS</b>' ) ) ; $ layout -> beginBlock ( ) ; foreach ( $ arguments as $ argument ) { $ this -> renderArgument ( $ layout , $ argument ) ; } $ layout -> endBlock ( ) ; $ layout -> add ( new EmptyLine ( ) ) ; }
Renders a list of arguments .
52,030
protected function renderOptions ( BlockLayout $ layout , array $ options ) { $ layout -> add ( new Paragraph ( '<b>OPTIONS</b>' ) ) ; $ layout -> beginBlock ( ) ; foreach ( $ options as $ option ) { $ this -> renderOption ( $ layout , $ option ) ; } $ layout -> endBlock ( ) ; $ layout -> add ( new EmptyLine ( ) ) ; }
Renders a list of options .
52,031
protected function renderOption ( BlockLayout $ layout , Option $ option ) { $ description = $ option -> getDescription ( ) ; $ defaultValue = $ option -> getDefaultValue ( ) ; if ( $ option -> isLongNamePreferred ( ) ) { $ preferredName = '--' . $ option -> getLongName ( ) ; $ alternativeName = $ option -> getShortName ( ) ? '-' . $ option -> getShortName ( ) : null ; } else { $ preferredName = '-' . $ option -> getShortName ( ) ; $ alternativeName = '--' . $ option -> getLongName ( ) ; } $ name = '<c1>' . $ preferredName . '</c1>' ; if ( $ alternativeName ) { $ name .= sprintf ( ' (%s)' , $ alternativeName ) ; } if ( $ option -> acceptsValue ( ) && null !== $ defaultValue && ( ! is_array ( $ defaultValue ) || count ( $ defaultValue ) ) ) { $ description .= sprintf ( ' <b>(default: %s)</b>' , $ this -> formatValue ( $ defaultValue ) ) ; } if ( $ option -> isMultiValued ( ) ) { $ description .= ' <b>(multiple values allowed)</b>' ; } $ layout -> add ( new LabeledParagraph ( $ name , $ description ) ) ; }
Renders an option .
52,032
protected function renderSynopsis ( BlockLayout $ layout , ArgsFormat $ argsFormat , $ appName , $ prefix = '' , $ lastOptional = false ) { $ nameParts = array ( ) ; $ argumentParts = array ( ) ; $ nameParts [ ] = '<u>' . ( $ appName ? : 'console' ) . '</u>' ; foreach ( $ argsFormat -> getCommandNames ( ) as $ commandName ) { $ nameParts [ ] = '<u>' . $ commandName -> toString ( ) . '</u>' ; } foreach ( $ argsFormat -> getCommandOptions ( ) as $ commandOption ) { $ nameParts [ ] = $ commandOption -> isLongNamePreferred ( ) ? '--' . $ commandOption -> getLongName ( ) : '-' . $ commandOption -> getShortName ( ) ; } if ( $ lastOptional ) { $ lastIndex = count ( $ nameParts ) - 1 ; $ nameParts [ $ lastIndex ] = '[' . $ nameParts [ $ lastIndex ] . ']' ; } foreach ( $ argsFormat -> getOptions ( false ) as $ option ) { if ( $ option -> isValueRequired ( ) ) { $ format = "%s\xC2\xA0<%s>" ; } elseif ( $ option -> isValueOptional ( ) ) { $ format = "%s\xC2\xA0[<%s>]" ; } else { $ format = '%s' ; } $ optionName = $ option -> isLongNamePreferred ( ) ? '--' . $ option -> getLongName ( ) : '-' . $ option -> getShortName ( ) ; $ argumentParts [ ] = sprintf ( '[' . $ format . ']' , $ optionName , $ option -> getValueName ( ) ) ; } foreach ( $ argsFormat -> getArguments ( ) as $ argument ) { $ argName = $ argument -> getName ( ) ; $ argumentParts [ ] = sprintf ( $ argument -> isRequired ( ) ? '<%s>' : '[<%s>]' , $ argName . ( $ argument -> isMultiValued ( ) ? '1' : '' ) ) ; if ( $ argument -> isMultiValued ( ) ) { $ argumentParts [ ] = sprintf ( '... [<%sN>]' , $ argName ) ; } } $ argsOpts = implode ( ' ' , $ argumentParts ) ; $ name = implode ( ' ' , $ nameParts ) ; $ layout -> add ( new LabeledParagraph ( $ prefix . $ name , $ argsOpts , 1 , false ) ) ; }
Renders the synopsis of a console command .
52,033
protected function formatValue ( $ value ) { if ( PHP_VERSION_ID < 50400 ) { return str_replace ( '\/' , '/' , json_encode ( $ value ) ) ; } return json_encode ( $ value , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ; }
Formats the default value of an argument or an option .
52,034
public function getOptions ( $ includeDefaults = true ) { $ options = $ this -> options ; if ( $ includeDefaults ) { foreach ( $ this -> format -> getOptions ( ) as $ option ) { $ name = $ option -> getLongName ( ) ; if ( ! array_key_exists ( $ name , $ options ) ) { $ options [ $ name ] = $ option -> acceptsValue ( ) ? $ option -> getDefaultValue ( ) : false ; } } } return $ options ; }
Returns all options .
52,035
public function addOptions ( array $ options ) { foreach ( $ options as $ name => $ value ) { $ this -> setOption ( $ name , $ value ) ; } return $ this ; }
Sets the values of multiple options .
52,036
public function getArgument ( $ name ) { $ argument = $ this -> format -> getArgument ( $ name ) ; if ( array_key_exists ( $ argument -> getName ( ) , $ this -> arguments ) ) { return $ this -> arguments [ $ argument -> getName ( ) ] ; } return $ argument -> getDefaultValue ( ) ; }
Returns the value of an argument .
52,037
public function getArguments ( $ includeDefaults = true ) { $ arguments = array ( ) ; foreach ( $ this -> format -> getArguments ( ) as $ argument ) { $ name = $ argument -> getName ( ) ; if ( array_key_exists ( $ name , $ this -> arguments ) ) { $ arguments [ $ name ] = $ this -> arguments [ $ name ] ; } elseif ( $ includeDefaults ) { $ arguments [ $ name ] = $ argument -> getDefaultValue ( ) ; } } return $ arguments ; }
Returns the values of all arguments .
52,038
public function setArgument ( $ name , $ value ) { $ argument = $ this -> format -> getArgument ( $ name ) ; if ( $ argument -> isMultiValued ( ) ) { $ value = ( array ) $ value ; foreach ( $ value as $ k => $ v ) { $ value [ $ k ] = $ argument -> parseValue ( $ v ) ; } } else { $ value = $ argument -> parseValue ( $ value ) ; } $ this -> arguments [ $ argument -> getName ( ) ] = $ value ; return $ this ; }
Sets the value of an argument .
52,039
public function addArguments ( array $ arguments ) { foreach ( $ arguments as $ name => $ value ) { $ this -> setArgument ( $ name , $ value ) ; } return $ this ; }
Sets the values of multiple arguments .
52,040
public static function find ( $ commandName , CommandCollection $ commands ) { $ threshold = 1e3 ; $ distancesByName = array ( ) ; $ actualNames = $ commands -> getNames ( true ) ; foreach ( $ actualNames as $ actualName ) { $ distance = levenshtein ( $ commandName , $ actualName ) ; $ isSimilar = $ distance <= ( strlen ( $ commandName ) / 3 ) ; $ isSubString = false !== strpos ( $ actualName , $ commandName ) ; if ( $ isSimilar || $ isSubString ) { $ distancesByName [ $ actualName ] = $ distance ; } } $ distancesByName = array_filter ( $ distancesByName , function ( $ distance ) use ( $ threshold ) { return $ distance < 2 * $ threshold ; } ) ; asort ( $ distancesByName ) ; $ suggestedNames = array_keys ( $ distancesByName ) ; return self :: filterDuplicates ( $ suggestedNames , $ commands ) ; }
Searches a command collection for similar names .
52,041
public function setLessBinary ( $ lessBinary ) { if ( null !== $ lessBinary ) { Assert :: string ( $ lessBinary , 'The less binary must be a string or null. Got: %s' ) ; Assert :: notEmpty ( $ lessBinary , 'The less binary must not be empty.' ) ; } $ this -> lessBinary = $ lessBinary ; }
Sets the less binary used to display the AsciiDoc page .
52,042
public function close ( ) { $ this -> input -> close ( ) ; $ this -> output -> close ( ) ; $ this -> errorOutput -> close ( ) ; }
Closes the input and the outputs .
52,043
public function setVerbosity ( $ verbosity ) { $ this -> output -> setVerbosity ( $ verbosity ) ; $ this -> errorOutput -> setVerbosity ( $ verbosity ) ; }
Sets the verbosity of the output .
52,044
public function setQuiet ( $ quiet ) { $ this -> output -> setQuiet ( $ quiet ) ; $ this -> errorOutput -> setQuiet ( $ quiet ) ; }
Sets whether all output should be suppressed .
52,045
public function setName ( $ name ) { if ( null !== $ name ) { Assert :: string ( $ name , 'The application name must be a string. Got: %s' ) ; Assert :: notEmpty ( $ name , 'The application name must not be empty.' ) ; Assert :: regex ( $ name , '~^[a-zA-Z0-9\-]+$~' , 'The application name must contain letters, numbers and hyphens only. Did you mean to call setDisplayName()?' ) ; } $ this -> name = $ name ; return $ this ; }
Sets the name of the application .
52,046
public function setDisplayName ( $ displayName ) { if ( null !== $ displayName ) { Assert :: string ( $ displayName , 'The display name must be a string. Got: %s' ) ; Assert :: notEmpty ( $ displayName , 'The display name must not be empty.' ) ; } $ this -> displayName = $ displayName ; return $ this ; }
Sets the application name as it is displayed in the help .
52,047
public function setVersion ( $ version ) { if ( null !== $ version ) { Assert :: string ( $ version , 'The application version must be a string. Got: %s' ) ; Assert :: notEmpty ( $ version , 'The application version must not be empty.' ) ; } $ this -> version = $ version ; return $ this ; }
Sets the version of the application .
52,048
public function setHelp ( $ help ) { if ( null !== $ help ) { Assert :: string ( $ help , 'The help text must be a string. Got: %s' ) ; Assert :: notEmpty ( $ help , 'The help text must not be empty.' ) ; } $ this -> help = $ help ; return $ this ; }
Sets the help text of the application .
52,049
public function addEventListener ( $ eventName , $ listener , $ priority = 0 ) { if ( ! $ this -> dispatcher ) { $ this -> dispatcher = new EventDispatcher ( ) ; } $ this -> dispatcher -> addListener ( $ eventName , $ listener , $ priority ) ; return $ this ; }
Adds a listener for the given event name .
52,050
public function addEventSubscriber ( EventSubscriberInterface $ subscriber ) { if ( ! $ this -> dispatcher ) { $ this -> dispatcher = new EventDispatcher ( ) ; } $ this -> dispatcher -> addSubscriber ( $ subscriber ) ; return $ this ; }
Adds an event subscriber to the dispatcher .
52,051
public function removeEventListener ( $ eventName , $ listener ) { if ( ! $ this -> dispatcher ) { $ this -> dispatcher = new EventDispatcher ( ) ; } $ this -> dispatcher -> removeListener ( $ eventName , $ listener ) ; return $ this ; }
Removes an event listener for the given event name .
52,052
public function removeEventSubscriber ( EventSubscriberInterface $ subscriber ) { if ( ! $ this -> dispatcher ) { $ this -> dispatcher = new EventDispatcher ( ) ; } $ this -> dispatcher -> removeSubscriber ( $ subscriber ) ; return $ this ; }
Removes an event subscriber from the dispatcher .
52,053
public function addStyle ( Style $ style ) { if ( ! $ this -> styleSet ) { $ this -> styleSet = new DefaultStyleSet ( ) ; } $ this -> styleSet -> add ( $ style ) ; return $ this ; }
Adds a style to the style set .
52,054
public function addStyles ( array $ styles ) { if ( ! $ this -> styleSet ) { $ this -> styleSet = new DefaultStyleSet ( ) ; } $ this -> styleSet -> merge ( $ styles ) ; return $ this ; }
Adds multiple styles to the style set .
52,055
public function beginCommand ( $ name ) { $ commandConfig = new CommandConfig ( $ name , $ this ) ; $ this -> commandConfigs [ ] = $ commandConfig ; return $ commandConfig ; }
Starts a configuration block for a command .
52,056
public function getCommandConfig ( $ name ) { foreach ( $ this -> commandConfigs as $ commandConfig ) { if ( $ name === $ commandConfig -> getName ( ) ) { return $ commandConfig ; } } throw NoSuchCommandException :: forCommandName ( $ name ) ; }
Returns the command configuration for a given name .
52,057
public function hasCommandConfig ( $ name ) { foreach ( $ this -> commandConfigs as $ commandConfig ) { if ( $ name === $ commandConfig -> getName ( ) ) { return true ; } } return false ; }
Returns whether the application has a command with a given name .
52,058
public function writeLine ( $ string , $ flags = null ) { if ( $ this -> mayWrite ( $ flags ) ) { $ string = rtrim ( $ string , PHP_EOL ) ; $ formatted = $ this -> formatOutput ? $ this -> format ( $ string ) : $ this -> removeFormat ( $ string ) ; $ this -> stream -> write ( $ formatted . PHP_EOL ) ; } }
Writes a line of text to the output stream .
52,059
public function writeRaw ( $ string , $ flags = null ) { if ( $ this -> mayWrite ( $ flags ) ) { $ this -> stream -> write ( $ string ) ; } }
Writes a string to the output stream without formatting .
52,060
public function writeLineRaw ( $ string , $ flags = null ) { if ( $ this -> mayWrite ( $ flags ) ) { $ this -> stream -> write ( rtrim ( $ string , PHP_EOL ) . PHP_EOL ) ; } }
Writes a line of text to the output stream without formatting .
52,061
public function setStream ( OutputStream $ stream ) { $ this -> stream = $ stream ; $ this -> formatOutput = $ stream -> supportsAnsi ( ) || ! ( $ this -> formatter instanceof AnsiFormatter ) ; }
Sets the underlying stream .
52,062
public function setVerbosity ( $ verbosity ) { Assert :: oneOf ( $ verbosity , array ( IO :: NORMAL , IO :: VERBOSE , IO :: VERY_VERBOSE , IO :: DEBUG ) , 'The verbosity must be one of IO::NORMAL, IO::VERBOSE, IO::VERY_VERBOSE and IO::DEBUG.' ) ; $ this -> verbosity = ( int ) $ verbosity ; }
Sets the verbosity level of the output .
52,063
protected function mayWrite ( $ flags ) { if ( $ this -> quiet ) { return false ; } if ( $ flags & IO :: VERBOSE ) { return $ this -> verbosity >= IO :: VERBOSE ; } if ( $ flags & IO :: VERY_VERBOSE ) { return $ this -> verbosity >= IO :: VERY_VERBOSE ; } if ( $ flags & IO :: DEBUG ) { return $ this -> verbosity >= IO :: DEBUG ; } return true ; }
Returns whether an output may be written for the given flags .
52,064
public function setCommandOptions ( array $ commandOptions ) { $ this -> commandOptions = array ( ) ; $ this -> commandOptionsByShortName = array ( ) ; $ this -> addCommandOptions ( $ commandOptions ) ; return $ this ; }
Sets the command options of the built format .
52,065
public function addCommandOption ( CommandOption $ commandOption ) { $ longName = $ commandOption -> getLongName ( ) ; $ shortName = $ commandOption -> getShortName ( ) ; $ longAliases = $ commandOption -> getLongAliases ( ) ; $ shortAliases = $ commandOption -> getShortAliases ( ) ; if ( $ this -> hasOption ( $ longName ) || $ this -> hasCommandOption ( $ longName ) ) { throw CannotAddOptionException :: existsAlready ( $ longName ) ; } foreach ( $ longAliases as $ shortAlias ) { if ( $ this -> hasOption ( $ shortAlias ) || $ this -> hasCommandOption ( $ shortAlias ) ) { throw CannotAddOptionException :: existsAlready ( $ shortAlias ) ; } } if ( $ shortName && ( $ this -> hasOption ( $ shortName ) || $ this -> hasCommandOption ( $ shortName ) ) ) { throw CannotAddOptionException :: existsAlready ( $ shortName ) ; } foreach ( $ shortAliases as $ shortAlias ) { if ( $ this -> hasOption ( $ shortAlias ) || $ this -> hasCommandOption ( $ shortAlias ) ) { throw CannotAddOptionException :: existsAlready ( $ shortAlias ) ; } } $ this -> commandOptions [ $ longName ] = $ commandOption ; if ( $ shortName ) { $ this -> commandOptionsByShortName [ $ shortName ] = $ commandOption ; } foreach ( $ longAliases as $ longAlias ) { $ this -> commandOptions [ $ longAlias ] = $ commandOption ; } foreach ( $ shortAliases as $ shortAlias ) { $ this -> commandOptionsByShortName [ $ shortAlias ] = $ commandOption ; } return $ this ; }
Adds a command option to the builder .
52,066
public function setArguments ( array $ arguments ) { $ this -> arguments = array ( ) ; $ this -> hasOptionalArg = false ; $ this -> hasMultiValuedArg = false ; $ this -> addArguments ( $ arguments ) ; return $ this ; }
Sets the arguments of the built format .
52,067
public function addArgument ( Argument $ argument ) { $ name = $ argument -> getName ( ) ; if ( $ this -> hasArgument ( $ name ) ) { throw CannotAddArgumentException :: existsAlready ( $ name ) ; } if ( $ this -> hasMultiValuedArgument ( ) ) { throw CannotAddArgumentException :: cannotAddAfterMultiValued ( ) ; } if ( $ argument -> isRequired ( ) && $ this -> hasOptionalArgument ( ) ) { throw CannotAddArgumentException :: cannotAddRequiredAfterOptional ( ) ; } if ( $ argument -> isMultiValued ( ) ) { $ this -> hasMultiValuedArg = true ; } if ( $ argument -> isOptional ( ) ) { $ this -> hasOptionalArg = true ; } $ this -> arguments [ $ name ] = $ argument ; return $ this ; }
Adds an argument at the end of the argument list .
52,068
public function getArgument ( $ name , $ includeBase = true ) { if ( ! is_int ( $ name ) ) { Assert :: string ( $ name , 'The argument name must be a string or integer. Got: %s' ) ; Assert :: notEmpty ( $ name , 'The argument name must not be empty.' ) ; } Assert :: boolean ( $ includeBase , 'The parameter $includeBase must be a boolean. Got: %s' ) ; if ( is_int ( $ name ) ) { $ arguments = array_values ( $ this -> getArguments ( $ includeBase ) ) ; if ( ! isset ( $ arguments [ $ name ] ) ) { throw NoSuchArgumentException :: forPosition ( $ name ) ; } } else { $ arguments = $ this -> getArguments ( $ includeBase ) ; if ( ! isset ( $ arguments [ $ name ] ) ) { throw NoSuchArgumentException :: forArgumentName ( $ name ) ; } } return $ arguments [ $ name ] ; }
Returns an argument by its name or position .
52,069
public function setOptions ( array $ options ) { $ this -> options = array ( ) ; $ this -> optionsByShortName = array ( ) ; $ this -> addOptions ( $ options ) ; return $ this ; }
Sets the options of the built format .
52,070
public function addOption ( Option $ option ) { $ longName = $ option -> getLongName ( ) ; $ shortName = $ option -> getShortName ( ) ; if ( $ this -> hasOption ( $ longName ) || $ this -> hasCommandOption ( $ longName ) ) { throw CannotAddOptionException :: existsAlready ( $ longName ) ; } if ( $ shortName && ( $ this -> hasOption ( $ shortName ) || $ this -> hasCommandOption ( $ shortName ) ) ) { throw CannotAddOptionException :: existsAlready ( $ shortName ) ; } $ this -> options [ $ longName ] = $ option ; if ( $ shortName ) { $ this -> optionsByShortName [ $ shortName ] = $ option ; } return $ this ; }
Adds an option at the end of the options list .
52,071
public function getHandler ( ) { if ( ! $ this -> handler ) { return $ this -> getDefaultHandler ( ) ; } if ( is_callable ( $ this -> handler ) ) { $ this -> handler = call_user_func ( $ this -> handler ) ; } return $ this -> handler ; }
Returns the command handler to execute when a command is run .
52,072
public function setHandler ( $ handler ) { if ( ! is_object ( $ handler ) && ! is_callable ( $ handler ) ) { throw new InvalidArgumentException ( sprintf ( 'Expected an object or a callable. Got: %s' , is_object ( $ handler ) ? get_class ( $ handler ) : gettype ( $ handler ) ) ) ; } $ this -> handler = $ handler ; return $ this ; }
Sets the command handler to execute when a command is run .
52,073
public function setHandlerMethod ( $ handlerMethod ) { Assert :: string ( $ handlerMethod , 'The handler method must be a string. Got: %s' ) ; Assert :: notEmpty ( $ handlerMethod , 'The handler method must not be empty.' ) ; $ this -> handlerMethod = $ handlerMethod ; return $ this ; }
Sets the method of the command handler that should be executed when the configured command is run .
52,074
protected function renderName ( BlockLayout $ layout , Application $ application ) { $ layout -> add ( new NameVersion ( $ application -> getConfig ( ) ) ) ; $ layout -> add ( new EmptyLine ( ) ) ; }
Renders the application name .
52,075
protected function renderCommand ( BlockLayout $ layout , Command $ command ) { $ description = $ command -> getConfig ( ) -> getDescription ( ) ; $ name = '<c1>' . $ command -> getName ( ) . '</c1>' ; $ layout -> add ( new LabeledParagraph ( $ name , $ description ) ) ; }
Renders a command in the Commands section .
52,076
protected function renderDescription ( BlockLayout $ layout , $ help ) { $ layout -> add ( new Paragraph ( '<b>DESCRIPTION</b>' ) ) -> beginBlock ( ) -> add ( new Paragraph ( $ help ) ) -> endBlock ( ) -> add ( new EmptyLine ( ) ) ; }
Renders the Description section .
52,077
public function parseArgs ( RawArgs $ args , $ lenient = null ) { if ( null === $ lenient ) { $ lenient = $ this -> config -> isLenientArgsParsingEnabled ( ) ; } return $ this -> config -> getArgsParser ( ) -> parseArgs ( $ args , $ this -> argsFormat , $ lenient ) ; }
Parses the raw console arguments and returns the parsed arguments .
52,078
public function run ( RawArgs $ args , IO $ io ) { return $ this -> handle ( $ this -> parseArgs ( $ args ) , $ io ) ; }
Executes the command for the given unparsed arguments .
52,079
public function handle ( Args $ args , IO $ io ) { $ processTitle = $ this -> config -> getProcessTitle ( ) ; $ this -> warnIfProcessTitleNotSupported ( $ processTitle , $ io ) ; if ( $ processTitle && ProcessTitle :: isSupported ( ) ) { ProcessTitle :: setProcessTitle ( $ processTitle ) ; try { $ statusCode = $ this -> doHandle ( $ args , $ io ) ; } catch ( Exception $ e ) { ProcessTitle :: resetProcessTitle ( ) ; throw $ e ; } ProcessTitle :: resetProcessTitle ( ) ; } else { $ statusCode = $ this -> doHandle ( $ args , $ io ) ; } if ( ! $ statusCode ) { return 0 ; } return min ( max ( ( int ) $ statusCode , 1 ) , 255 ) ; }
Executes the command for the given parsed arguments .
52,080
private function getBaseFormat ( ) { if ( $ this -> parentCommand ) { return $ this -> parentCommand -> getArgsFormat ( ) ; } if ( $ this -> application ) { return $ this -> application -> getGlobalArgsFormat ( ) ; } return null ; }
Returns the inherited arguments format of the command .
52,081
private function addSubCommand ( SubCommandConfig $ config ) { if ( ! $ config -> isEnabled ( ) ) { return ; } $ this -> validateSubCommandName ( $ config ) ; $ command = new self ( $ config , $ this -> application , $ this ) ; $ this -> subCommands -> add ( $ command ) ; if ( $ config -> isDefault ( ) ) { $ this -> defaultSubCommands -> add ( $ command ) ; } if ( ! $ config -> isAnonymous ( ) ) { $ this -> namedSubCommands -> add ( $ command ) ; } }
Adds a sub - command .
52,082
public function add ( LabeledParagraph $ paragraph , $ indentation = 0 ) { if ( $ paragraph -> isAligned ( ) ) { $ this -> paragraphs [ ] = $ paragraph ; $ this -> indentations [ ] = $ indentation ; } }
Adds a labeled paragraph to the alignment .
52,083
public function align ( Formatter $ formatter , $ indentation = 0 ) { $ this -> textOffset = 0 ; foreach ( $ this -> paragraphs as $ i => $ item ) { $ label = $ formatter -> removeFormat ( $ item -> getLabel ( ) ) ; $ textOffset = $ this -> indentations [ $ i ] + strlen ( $ label ) + $ item -> getPadding ( ) ; $ this -> textOffset = max ( $ this -> textOffset , $ textOffset ) ; } $ this -> textOffset += $ indentation ; }
Calculates the text offset based on all labels in the alignment .
52,084
protected function renderSubCommand ( BlockLayout $ layout , Command $ command ) { $ config = $ command -> getConfig ( ) ; $ description = $ config -> getDescription ( ) ; $ help = $ config -> getHelp ( ) ; $ arguments = $ command -> getArgsFormat ( ) -> getArguments ( false ) ; $ options = $ command -> getArgsFormat ( ) -> getOptions ( false ) ; if ( $ config instanceof OptionCommandConfig ) { if ( $ config -> isLongNamePreferred ( ) ) { $ preferredName = '--<u>' . $ config -> getLongName ( ) . '</u>' ; $ alternativeName = $ config -> getShortName ( ) ? '-<u>' . $ config -> getShortName ( ) . '</u>' : null ; } else { $ preferredName = '-<u>' . $ config -> getShortName ( ) . '</u>' ; $ alternativeName = '--<u>' . $ config -> getLongName ( ) . '</u>' ; } $ name = $ preferredName ; if ( $ alternativeName ) { $ name .= ' (' . $ alternativeName . ')' ; } } else { $ name = '<u>' . $ command -> getName ( ) . '</u>' ; } $ layout -> add ( new Paragraph ( $ name ) ) ; $ layout -> beginBlock ( ) ; if ( $ description ) { $ this -> renderSubCommandDescription ( $ layout , $ description ) ; } if ( $ help ) { $ this -> renderSubCommandHelp ( $ layout , $ help ) ; } if ( $ arguments ) { $ this -> renderSubCommandArguments ( $ layout , $ arguments ) ; } if ( $ options ) { $ this -> renderSubCommandOptions ( $ layout , $ options ) ; } if ( ! $ description && ! $ help && ! $ arguments && ! $ options ) { $ layout -> add ( new EmptyLine ( ) ) ; } $ layout -> endBlock ( ) ; }
Renders a sub - command in the Commands section .
52,085
protected function renderSubCommandDescription ( BlockLayout $ layout , $ description ) { $ layout -> add ( new Paragraph ( $ description ) ) ; $ layout -> add ( new EmptyLine ( ) ) ; }
Renders the description of a sub - command .
52,086
protected function renderSubCommandHelp ( BlockLayout $ layout , $ help ) { $ layout -> add ( new Paragraph ( $ help ) ) ; $ layout -> add ( new EmptyLine ( ) ) ; }
Renders the help text of a sub - command .
52,087
protected function renderSubCommandArguments ( BlockLayout $ layout , array $ arguments ) { foreach ( $ arguments as $ argument ) { $ this -> renderArgument ( $ layout , $ argument ) ; } $ layout -> add ( new EmptyLine ( ) ) ; }
Renders the argument descriptions of a sub - command .
52,088
protected function renderSubCommandOptions ( BlockLayout $ layout , array $ options ) { foreach ( $ options as $ option ) { $ this -> renderOption ( $ layout , $ option ) ; } $ layout -> add ( new EmptyLine ( ) ) ; }
Renders the option descriptions of a sub - command .
52,089
private static function getFactory ( string $ type ) { if ( ! empty ( self :: $ factories [ $ type ] ) ) { return self :: $ factories [ $ type ] ; } if ( ! empty ( self :: $ factory ) ) { return self :: $ factories [ $ type ] = self :: $ factory ; } foreach ( self :: $ strategies as $ className ) { if ( is_array ( $ className ) && isset ( $ className [ $ type ] ) ) { $ className = $ className [ $ type ] ; if ( class_exists ( $ className ) ) { return self :: $ factories [ $ type ] = new $ className ( ) ; } continue ; } if ( ! class_exists ( $ className ) ) { continue ; } if ( strpos ( $ className , __NAMESPACE__ ) === 0 && ! $ className :: isInstalled ( ) ) { continue ; } return self :: $ factories [ $ type ] = self :: $ factory = new $ className ( ) ; } throw new RuntimeException ( 'No PSR-7 library detected' ) ; }
Create the PSR - 17 factories or throw an exception
52,090
public static function setStrategies ( array $ strategies = null ) { self :: $ factory = null ; self :: $ factories = [ ] ; self :: $ strategies = $ strategies ; }
Change the strategies
52,091
public static function createResponse ( int $ code = 200 , string $ reasonPhrase = '' ) : ResponseInterface { return self :: getResponseFactory ( ) -> createResponse ( $ code , $ reasonPhrase ) ; }
Creates a Response instance .
52,092
public static function createServerRequest ( string $ method , $ uri , array $ serverParams = [ ] ) : ServerRequestInterface { return self :: getServerRequestFactory ( ) -> createServerRequest ( $ method , $ uri , $ serverParams ) ; }
Creates a ServerRequest instance .
52,093
public function add ( Style $ style ) { if ( ! $ style -> getTag ( ) ) { throw new LogicException ( 'The tag of a style added to the style set must be set.' ) ; } $ this -> styles [ $ style -> getTag ( ) ] = $ style ; }
Adds a style .
52,094
public function get ( $ tag ) { if ( ! isset ( $ this -> styles [ $ tag ] ) ) { throw new OutOfBoundsException ( sprintf ( 'The style tag "%s" does not exist.' , $ tag ) ) ; } return $ this -> styles [ $ tag ] ; }
Returns the style with the given tag .
52,095
public function match ( $ string ) { return $ this -> string === $ string || in_array ( $ string , $ this -> aliases , true ) ; }
Returns whether a string matches the command name or one of its aliases .
52,096
public static function run ( array $ stack , ServerRequestInterface $ request = null ) : ResponseInterface { if ( $ request === null ) { $ request = Factory :: createServerRequest ( 'GET' , '/' ) ; } return ( new static ( $ stack ) ) -> dispatch ( $ request ) ; }
Static helper to create and dispatch a request .
52,097
public function dispatch ( ServerRequestInterface $ request ) : ResponseInterface { $ resolved = $ this -> resolve ( 0 ) ; return $ resolved -> handle ( $ request ) ; }
Dispatches the middleware stack and returns the resulting ResponseInterface .
52,098
public function launchProcess ( $ command , array $ arguments = array ( ) , $ killable = true ) { $ this -> installSignalHandlers ( $ killable ) ; $ exitCode = $ this -> run ( $ command , $ arguments ) ; $ this -> restoreSignalHandlers ( $ killable ) ; return $ exitCode ; }
Launches a process in the foreground .
52,099
private function adaptOption ( Option $ option ) { $ mode = null ; if ( $ option -> isMultiValued ( ) ) { $ mode |= InputOption :: VALUE_IS_ARRAY ; } if ( $ option -> isValueOptional ( ) ) { $ mode |= InputOption :: VALUE_OPTIONAL ; } if ( $ option -> isValueRequired ( ) ) { $ mode |= InputOption :: VALUE_REQUIRED ; } return new InputOption ( $ option -> getLongName ( ) , $ option -> getShortName ( ) , $ mode , $ option -> getDescription ( ) , $ option -> getDefaultValue ( ) ) ; }
Creates an input option for the given option .