CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Namespace Console

Namespaces

  • Cake\Console\Command
  • Cake\Console\Exception
  • Cake\Console\Helper
  • Cake\Console\TestSuite

Interfaces

  • CommandCollectionAwareInterface

    An interface for shells that take a CommandCollection during initialization.

  • CommandFactoryInterface

    An interface for abstracting creation of command and shell instances.

  • CommandHiddenInterface

    Marker interface for commands that should be hidden from the help output and shell completion while remaining fully executable.

    Example

    use Cake\Command\Command;
    use Cake\Console\CommandHiddenInterface;
    
    class InternalMaintenanceCommand extends Command implements CommandHiddenInterface
    {
        // Command implementation
    }
  • CommandInterface

    Describe the interface between a command and the surrounding console libraries.

  • ConsoleIoInterface

    A wrapper around the various IO operations shell tasks need to do.

    Packages up the stdout, stderr, and stdin streams providing a simple consistent interface for shells to use. This class also makes mocking streams easy to do in unit tests.

Classes

  • Arguments

    Provides an interface for interacting with a command's options and arguments.

  • BaseCommand

    Base class for console commands.

    Provides hooks for common command features:

    • initialize Acts as a post-construct hook.
    • buildOptionParser Build/Configure the option parser for your command.
    • execute Execute your command with parsed Arguments and ConsoleIo

    Life cycle callbacks

    CakePHP fires a number of life cycle callbacks during each command execution. By implementing a method you can receive the related events. The available callbacks are:

    • beforeExecute(EventInterface $event) Called immediately prior to the command's run method. This is a good place to do general logic that applies to command setup.
    • afterExecute(EventInterface $event) Called immediately after the command's run method, unless an exception occurs.
  • CommandCollection

    Collection for Commands.

    Used by Applications to specify their console commands. CakePHP will use the mapped commands to construct and dispatch shell commands.

  • CommandFactory

    This is a factory for creating Command instances.

    This factory can be replaced or extended if you need to customize building your command objects.

  • CommandRunner

    Run CLI commands for the provided application.

  • CommandScanner

    Scans the filesystem for command classes.

    Implementation detail behind CommandCollection's discovery methods. Not part of the supported public API - use CommandCollection (e.g. discoverDirectory()) instead.

  • ConsoleInput

    Object wrapper for interacting with stdin

  • ConsoleInputArgument

    An object to represent a single argument used in the command line. ConsoleOptionParser creates these when you use addArgument()

  • ConsoleInputOption

    An object to represent a single option used in the command line. ConsoleOptionParser creates these when you use addOption()

  • ConsoleIo

    A wrapper around the various IO operations shell tasks need to do.

    Packages up the stdout, stderr, and stdin streams providing a simple consistent interface for shells to use. This class also makes mocking streams easy to do in unit tests.

  • ConsoleOptionParser

    Handles parsing the ARGV in the command line and provides support for GetOpt compatible option definition. Provides a builder pattern implementation for creating shell option parsers.

    Options

    Named arguments come in two forms, long and short. Long arguments are preceded by two - and give a more verbose option name. i.e. --version. Short arguments are preceded by one - and are only one character long. They usually match with a long option, and provide a more terse alternative.

    Using Options

    Options can be defined with both long and short forms. By using $parser->addOption() you can define new options. The name of the option is used as its long form, and you can supply an additional short form, with the short option. Short options should only be one letter long. Using more than one letter for a short option will raise an exception.

    Calling options can be done using syntax similar to most *nix command line tools. Long options can either include an = or leave it out.

    cake my_command --connection default --name=something

    Short options can be defined singly or in groups.

    cake my_command -cn

    Short options can be combined into groups as seen above. Each letter in a group will be treated as a separate option. The previous example is equivalent to:

    cake my_command -c -n

    Short options can also accept values:

    cake my_command -c default

    Positional arguments

    If no positional arguments are defined, all of them will be parsed. If you define positional arguments any arguments greater than those defined will cause exceptions. Additionally you can declare arguments as optional, by setting the required param to false.

    $parser->addArgument('model', ['required' => false]);

    Providing Help text

    By providing help text for your positional arguments and named arguments, the ConsoleOptionParser can generate a help display for you. You can view the help for shells by using the --help or -h switch.

  • ConsoleOutput

    Object wrapper for outputting information from a shell application. Can be connected to any stream resource that can be used with fopen()

    Can generate colorized output on consoles that support it. There are a few built in styles

    • error Error messages.
    • warning Warning messages.
    • info Informational messages.
    • comment Additional text.
    • question Magenta text used for user prompts
    • success Green foreground text
    • info.bg Cyan background with black text
    • warning.bg Yellow background with black text
    • error.bg Red background with black text
    • success.bg Green background with black text

    By defining styles with addStyle() you can create custom console styles.

    Using styles in output

    You can format console output using tags with the name of the style to apply. From inside a shell object

    $this->out('<warning>Overwrite:</warning> foo.php was overwritten.');

    This would create orange 'Overwrite:' text, while the rest of the text would remain the normal color. See ConsoleOutput::styles() to learn more about defining your own styles. Nested styles are not supported at this time.

  • HelpFormatter

    HelpFormatter formats help for console shells. Can format to either text or XML formats. Uses ConsoleOptionParser methods to generate help.

    Generally not directly used. Using $parser->help($command, 'xml'); is usually how you would access help. Or via the --help=xml option on the command line.

    Xml output is useful for integration with other tools like IDE's or other build tools.

  • Helper

    Base class for Helpers.

    Console Helpers allow you to package up reusable blocks of Console output logic. For example creating tables, progress bars or ascii art.

  • HelperRegistry

    Registry for Helpers. Provides features for lazily loading helpers.

OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs