CLIRequest Class

If a request comes from a command line invocation, the request object is actually aCLIRequest. It behaves the same as a conventional requestbut adds some accessor methods for convenience.

Additional Accessors

getSegments()

Returns an array of the command line arguments deemed to be part of a path:

  1. // command line: php index.php users 21 profile -foo bar
  2. echo $request->getSegments(); // ['users', '21', 'profile']

getPath()

Returns the reconstructed path as a string:

  1. // command line: php index.php users 21 profile -foo bar
  2. echo $request->getPath(); // users/21/profile

getOptions()

Returns an array of the command line arguments deemed to be options:

  1. // command line: php index.php users 21 profile -foo bar
  2. echo $request->getOptions(); // ['foo' => 'bar']

getOption($which)

Returns the value of a specific command line argument deemed to be an option:

  1. // command line: php index.php users 21 profile -foo bar
  2. echo $request->getOption('foo'); // bar
  3. echo $request->getOption('notthere'); // NULL

getOptionString()

Returns the reconstructed command line string for the options:

  1. // command line: php index.php users 21 profile -foo bar
  2. echo $request->getOptionPath(); // -foo bar