CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 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

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • Arguments
  • Command
  • CommandCollection
  • CommandFactory
  • CommandRunner
  • ConsoleErrorHandler
  • ConsoleInput
  • ConsoleInputArgument
  • ConsoleInputOption
  • ConsoleInputSubcommand
  • ConsoleIo
  • ConsoleOptionParser
  • ConsoleOutput
  • Helper
  • HelperRegistry
  • HelpFormatter
  • Shell
  • ShellDispatcher
  • TaskRegistry

Interfaces

  • CommandCollectionAwareInterface
  • CommandFactoryInterface
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.6.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Console;
 16: 
 17: /**
 18:  * Provides an interface for interacting with
 19:  * a command's options and arguments.
 20:  */
 21: class Arguments
 22: {
 23:     /**
 24:      * Positional argument name map
 25:      *
 26:      * @var string[]
 27:      */
 28:     protected $argNames;
 29: 
 30:     /**
 31:      * Positional arguments.
 32:      *
 33:      * @var string[]
 34:      */
 35:     protected $args;
 36: 
 37:     /**
 38:      * Named options
 39:      *
 40:      * @var array
 41:      */
 42:     protected $options;
 43: 
 44:     /**
 45:      * Constructor
 46:      *
 47:      * @param string[] $args Positional arguments
 48:      * @param array $options Named arguments
 49:      * @param string[] $argNames List of argument names. Order is expected to be
 50:      *  the same as $args.
 51:      */
 52:     public function __construct(array $args, array $options, array $argNames)
 53:     {
 54:         $this->args = $args;
 55:         $this->options = $options;
 56:         $this->argNames = $argNames;
 57:     }
 58: 
 59:     /**
 60:      * Get all positional arguments.
 61:      *
 62:      * @return string[]
 63:      */
 64:     public function getArguments()
 65:     {
 66:         return $this->args;
 67:     }
 68: 
 69:     /**
 70:      * Get positional arguments by index.
 71:      *
 72:      * @param int $index The argument index to access.
 73:      * @return string|null The argument value or null
 74:      */
 75:     public function getArgumentAt($index)
 76:     {
 77:         if ($this->hasArgumentAt($index)) {
 78:             return $this->args[$index];
 79:         }
 80: 
 81:         return null;
 82:     }
 83: 
 84:     /**
 85:      * Check if a positional argument exists
 86:      *
 87:      * @param int $index The argument index to check.
 88:      * @return bool
 89:      */
 90:     public function hasArgumentAt($index)
 91:     {
 92:         return isset($this->args[$index]);
 93:     }
 94: 
 95:     /**
 96:      * Check if a positional argument exists by name
 97:      *
 98:      * @param string $name The argument name to check.
 99:      * @return bool
100:      */
101:     public function hasArgument($name)
102:     {
103:         $offset = array_search($name, $this->argNames, true);
104:         if ($offset === false) {
105:             return false;
106:         }
107: 
108:         return isset($this->args[$offset]);
109:     }
110: 
111:     /**
112:      * Check if a positional argument exists by name
113:      *
114:      * @param string $name The argument name to check.
115:      * @return string|null
116:      */
117:     public function getArgument($name)
118:     {
119:         $offset = array_search($name, $this->argNames, true);
120:         if ($offset === false || !isset($this->args[$offset])) {
121:             return null;
122:         }
123: 
124:         return $this->args[$offset];
125:     }
126: 
127:     /**
128:      * Get an array of all the options
129:      *
130:      * @return array
131:      */
132:     public function getOptions()
133:     {
134:         return $this->options;
135:     }
136: 
137:     /**
138:      * Get an option's value or null
139:      *
140:      * @param string $name The name of the option to check.
141:      * @return string|int|bool|null The option value or null.
142:      */
143:     public function getOption($name)
144:     {
145:         if (isset($this->options[$name])) {
146:             return $this->options[$name];
147:         }
148: 
149:         return null;
150:     }
151: 
152:     /**
153:      * Check if an option is defined and not null.
154:      *
155:      * @param string $name The name of the option to check.
156:      * @return bool
157:      */
158:     public function hasOption($name)
159:     {
160:         return isset($this->options[$name]);
161:     }
162: }
163: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs