Class ExtractTask
Language string extractor
Constants
Property Summary
- 
        $OptionParser publicCake\Console\ConsoleOptionParserAn instance of ConsoleOptionParser that has been configured for this class. 
- 
        $Tasks publicCake\Console\TaskRegistryTask Collection for the command, used to create Tasks. 
- 
        $_exclude protectedarrayAn array of directories to exclude. 
- 
        $_extractCore protectedboolHolds whether this call should extract the CakePHP Lib messages 
- 
        $_file protectedstringCurrent file being processed 
- 
        $_files protectedarrayFiles from where to extract 
- 
        $_io protectedCake\Console\ConsoleIoConsoleIo instance. 
- 
        $_merge protectedboolMerge all domain strings into the default.pot file 
- 
        $_modelFactories protectedarrayA list of overridden model factory functions. 
- 
        $_modelType protectedstringThe model type to use. 
- 
        $_output protectedstringDestination path 
- 
        $_paths protectedarrayPaths to use when looking for strings 
- 
        $_storage protectedarrayContains all content waiting to be write 
- 
        $_tableLocator protectedCake\ORM\Locator\LocatorInterfaceTable locator instance 
- 
        $_taskMap protectedarrayNormalized map of tasks. 
- 
        $_tokens protectedarrayExtracted tokens 
- 
        $_translations protectedarrayExtracted strings indexed by domain. 
- 
        $_validationDomain protectedboolHolds the validation string domain to use for validation messages when extracting 
- 
        $args publicarrayContains arguments parsed from the command line. 
- 
        $command publicstringThe command (method/task) that is being run. 
- 
        $interactive publicboolIf true, the script will ask for permission to perform actions. 
- 
        $modelClass publicstringThis object's primary model class name. Should be a plural form. CakePHP will not inflect the name. 
- 
        $name publicstringThe name of the shell in camelized. 
- 
        $params publicarrayContains command switches parsed from the command line. 
- 
        $plugin publicstringThe name of the plugin the shell belongs to. Is automatically set by ShellDispatcher when a shell is constructed. 
- 
        $taskNames publicarrayContains the loaded tasks 
- 
        $tasks publicarrayContains tasks to load and instantiate 
Method Summary
- 
          __construct() publicConstructs this Shell instance. 
- 
          __debugInfo() publicReturns an array that can be used to describe the internal state of this object. 
- 
          __get() publicOverload get for lazy building of tasks 
- 
          _addTranslation() protectedAdd a translation to the internal translations property 
- 
          _buildFiles() protectedBuild the translate template file contents out of obtained strings 
- 
          _displayHelp() protectedDisplay the help in the correct format 
- 
          _extract() protectedExtract text 
- 
          _extractTokens() protectedExtract tokens out of all files to be processed 
- 
          _formatString() protectedFormat a string to be added as a translatable string 
- 
          _getPaths() protectedMethod to interact with the User and get path selections. 
- 
          _getStrings() protectedGet the strings from the position forward 
- 
          _isExtractingApp() protectedReturns whether this execution is meant to extract string only from directories in folder represented by the APP constant, i.e. this task is extracting strings from same application. 
- 
          _isPathUsable() protectedChecks whether or not a given path is usable for writing. 
- 
          _markerError() protectedIndicate an invalid marker on a processed file 
- 
          _mergeProperty() protectedMerge a single property with the values declared in all parent classes. 
- 
          _mergePropertyData() protectedMerge each of the keys in a property together. 
- 
          _mergeVars() protectedMerge the list of $properties with all parent classes of the current class. 
- 
          _parse() protectedParse tokens 
- 
          _searchFiles() protectedSearch files that may contain translatable strings 
- 
          _setModelClass() protectedSet the modelClass and modelKey properties based on conventions. 
- 
          _setOutputLevel() protectedSet the output level based on the parameters. 
- 
          _stop() protectedStop execution of the current script. Raises a StopException to try and halt the execution. 
- 
          _store() protectedPrepare a file to be stored 
- 
          _welcome() protectedNo welcome message. 
- 
          _writeFiles() protectedWrite the files that need to be stored 
- 
          _writeHeader() protectedBuild the translation template header 
- 
          abort() publicDisplays a formatted error message and exits the application with status code 1 
- 
          clear() publicClear the console 
- 
          createFile() publicCreates a file at given path 
- 
          dispatchShell() publicDispatch a command to another Shell. Similar to Object::requestAction() but intended for running shells from other shells. 
- 
          err() publicOutputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline. 
- 
          error() public deprecatedDisplays a formatted error message and exits the application with status code 1 
- 
          getOptionParser() publicGets the option parser instance and configures it. 
- 
          hasMethod() publicCheck to see if this shell has a callable method by the given name. 
- 
          hasTask() publicCheck to see if this shell has a task with the provided name. 
- 
          helper() publicRender a Console Helper 
- 
          hr() publicOutputs a series of minus characters to the standard output, acts as a visual separator. 
- 
          in() publicPrompts the user for input, and returns it. 
- 
          info() publicConvenience method for out() that wraps message between tag 
- 
          initialize() publicInitializes the Shell acts as constructor for subclasses allows configuration of tasks prior to shell execution 
- 
          io() publicGet/Set the io object for this shell. 
- 
          loadModel() publicLoads and constructs repository objects required by this object 
- 
          loadTasks() publicLoads tasks defined in public $tasks 
- 
          log() publicConvenience method to write a message to Log. See Log::write() for more information on writing to logs. 
- 
          main() publicExecution method always used for tasks 
- 
          modelFactory() publicOverride a existing callable to generate repositories of a given type. 
- 
          modelType() publicSet or get the model type to be used by this class 
- 
          nl() publicReturns a single or multiple linefeeds sequences. 
- 
          out() publicOutputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline. 
- 
          param() publicSafely access the values in $this->params. 
- 
          parseDispatchArguments() publicParses the arguments for the dispatchShell() method. 
- 
          quiet() publicOutput at all levels. 
- 
          runCommand() publicRuns the Shell with the provided argv. 
- 
          shortPath() publicMakes absolute file path easier to read 
- 
          startup() publicStarts up the Shell and displays the welcome message. Allows for checking and configuring prior to command or main execution 
- 
          success() publicConvenience method for out() that wraps message between tag 
- 
          tableLocator() publicSets the table locator. If no parameters are passed, it will return the currently used locator. 
- 
          verbose() publicOutput at the verbose level. 
- 
          warn() publicConvenience method for err() that wraps message between tag 
- 
          wrapText() publicWrap a block of text. Allows you to set the width, and indenting on a block of text. 
Method Detail
__construct() ¶ public
__construct(Cake\Console\ConsoleIo|null $io = null)Constructs this Shell instance.
Parameters
- 
                Cake\Console\ConsoleIo|null$io optional
- An io instance. 
Links
__debugInfo() ¶ public
__debugInfo(): arrayReturns an array that can be used to describe the internal state of this object.
Returns
array__get() ¶ public
__get(string $name): Cake\Console\ShellOverload get for lazy building of tasks
Parameters
- 
                string$name
- The task to get. 
Returns
Cake\Console\ShellObject of Task
_addTranslation() ¶ protected
_addTranslation(string $domain, string $msgid, array $details = []): voidAdd a translation to the internal translations property
Takes care of duplicate translations
Parameters
- 
                string$domain
- The domain 
- 
                string$msgid
- The message string 
- 
                array$details optional
- Context and plural form if any, file and line references 
Returns
void_buildFiles() ¶ protected
_buildFiles(): voidBuild the translate template file contents out of obtained strings
Returns
void_displayHelp() ¶ protected
_displayHelp(string $command): int|boolDisplay the help in the correct format
Parameters
- 
                string$command
- The command to get help for. 
Returns
int|boolThe number of bytes returned from writing to stdout.
_extractTokens() ¶ protected
_extractTokens(): voidExtract tokens out of all files to be processed
Returns
void_formatString() ¶ protected
_formatString(string $string): stringFormat a string to be added as a translatable string
Parameters
- 
                string$string
- String to format 
Returns
stringFormatted string
_getPaths() ¶ protected
_getPaths(): voidMethod to interact with the User and get path selections.
Returns
void_getStrings() ¶ protected
_getStrings(int $position, int $target): arrayGet the strings from the position forward
Parameters
- 
                int$position
- Actual position on tokens array 
- 
                int$target
- Number of strings to extract 
Returns
arrayStrings extracted
_isExtractingApp() ¶ protected
_isExtractingApp(): boolReturns whether this execution is meant to extract string only from directories in folder represented by the APP constant, i.e. this task is extracting strings from same application.
Returns
bool_isPathUsable() ¶ protected
_isPathUsable(string $path): boolChecks whether or not a given path is usable for writing.
Parameters
- 
                string$path
- Path to folder 
Returns
booltrue if it exists and is writable, false otherwise
_markerError() ¶ protected
_markerError(string $file, int $line, string $marker, int $count): voidIndicate an invalid marker on a processed file
Parameters
- 
                string$file
- File where invalid marker resides 
- 
                int$line
- Line number 
- 
                string$marker
- Marker found 
- 
                int$count
- Count 
Returns
void_mergeProperty() ¶ protected
_mergeProperty(string $property, array $parentClasses, array $options): voidMerge a single property with the values declared in all parent classes.
Parameters
- 
                string$property
- The name of the property being merged. 
- 
                array$parentClasses
- An array of classes you want to merge with. 
- 
                array$options
- Options for merging the property, see _mergeVars() 
Returns
void_mergePropertyData() ¶ protected
_mergePropertyData(array $current, array $parent, bool $isAssoc): mixedMerge each of the keys in a property together.
Parameters
- 
                array$current
- The current merged value. 
- 
                array$parent
- The parent class' value. 
- 
                bool$isAssoc
- Whether or not the merging should be done in associative mode. 
Returns
mixedThe updated value.
_mergeVars() ¶ protected
_mergeVars(array $properties, array $options = []): voidMerge the list of $properties with all parent classes of the current class.
Options:
- associative- A list of properties that should be treated as associative arrays. Properties in this list will be passed through Hash::normalize() before merging.
Parameters
- 
                array$properties
- An array of properties and the merge strategy for them. 
- 
                array$options optional
- The options to use when merging properties. 
Returns
void_parse() ¶ protected
_parse(string $functionName, array $map): voidParse tokens
Parameters
- 
                string$functionName
- Function name that indicates translatable string (e.g: '__') 
- 
                array$map
- Array containing what variables it will find (e.g: domain, singular, plural) 
Returns
void_searchFiles() ¶ protected
_searchFiles(): voidSearch files that may contain translatable strings
Returns
void_setModelClass() ¶ protected
_setModelClass(string $name): voidSet the modelClass and modelKey properties based on conventions.
If the properties are already set they will not be overwritten
Parameters
- 
                string$name
- Class name. 
Returns
void_setOutputLevel() ¶ protected
_setOutputLevel(): voidSet the output level based on the parameters.
This reconfigures both the output level for out() and the configured stdout/stderr logging
Returns
void_stop() ¶ protected
_stop(int|string $status = self::CODE_SUCCESS): voidStop execution of the current script. Raises a StopException to try and halt the execution.
Parameters
- 
                int|string$status optional
- see http://php.net/exit for values 
Returns
voidThrows
Cake\Console\Exception\StopException_store() ¶ protected
_store(string $domain, string $header, string $sentence): voidPrepare a file to be stored
Parameters
- 
                string$domain
- The domain 
- 
                string$header
- The header content. 
- 
                string$sentence
- The sentence to store. 
Returns
void_writeHeader() ¶ protected
_writeHeader(): stringBuild the translation template header
Returns
stringTranslation template header
abort() ¶ public
abort(string $message, int $exitCode = self::CODE_ERROR): voidDisplays a formatted error message and exits the application with status code 1
Parameters
- 
                string$message
- The error message 
- 
                int$exitCode optional
- The exit code for the shell task. 
Returns
voidThrows
Cake\Console\Exception\StopExceptionLinks
clear() ¶ public
clear(): voidClear the console
Returns
voidLinks
createFile() ¶ public
createFile(string $path, string $contents): boolCreates a file at given path
Parameters
- 
                string$path
- Where to put the file. 
- 
                string$contents
- Content to put in the file. 
Returns
boolSuccess
Links
dispatchShell() ¶ public
dispatchShell(): intDispatch a command to another Shell. Similar to Object::requestAction() but intended for running shells from other shells.
Usage:
With a string command:
return $this->dispatchShell('schema create DbAcl');Avoid using this form if you have string arguments, with spaces in them. The dispatched will be invoked incorrectly. Only use this form for simple command dispatching.
With an array command:
return $this->dispatchShell('schema', 'create', 'i18n', '--dry');With an array having two key / value pairs:
- commandcan accept either a string or an array. Represents the command to dispatch
- extracan accept an array of extra parameters to pass on to the dispatcher. This parameters will be available in the- paramproperty of the called- Shell
return $this->dispatchShell([ 'command' => 'schema create DbAcl', 'extra' => ['param' => 'value'] ]);
or
return $this->dispatchShell([ 'command' => ['schema', 'create', 'DbAcl'], 'extra' => ['param' => 'value'] ]);
Returns
intThe cli command exit code. 0 is success.
Links
err() ¶ public
err(string|array|null $message = null, int $newlines = 1): int|boolOutputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
Parameters
- 
                string|array|null$message optional
- A string or an array of strings to output 
- 
                int$newlines optional
- Number of newlines to append 
Returns
int|boolThe number of bytes returned from writing to stderr.
error() ¶ public
error(string $title, string|null $message = null, int $exitCode = self::CODE_ERROR): intDisplays a formatted error message and exits the application with status code 1
Parameters
- 
                string$title
- Title of the error 
- 
                string|null$message optional
- An optional error message 
- 
                int$exitCode optional
- The exit code for the shell task. 
Returns
intError code
Throws
Cake\Console\Exception\StopExceptionLinks
getOptionParser() ¶ public
getOptionParser(): Cake\Console\ConsoleOptionParserGets the option parser instance and configures it.
By overriding this method you can configure the ConsoleOptionParser before returning it.
Returns
Cake\Console\ConsoleOptionParserhasMethod() ¶ public
hasMethod(string $name): boolCheck to see if this shell has a callable method by the given name.
Parameters
- 
                string$name
- The method name to check. 
Returns
boolLinks
hasTask() ¶ public
hasTask(string $task): boolCheck to see if this shell has a task with the provided name.
Parameters
- 
                string$task
- The task name to check. 
Returns
boolSuccess
Links
helper() ¶ public
helper(string $name, array $settings = []): Cake\Console\HelperRender a Console Helper
Create and render the output for a helper object. If the helper object has not already been loaded, it will be loaded and constructed.
Parameters
- 
                string$name
- The name of the helper to render 
- 
                array$settings optional
- Configuration data for the helper. 
Returns
Cake\Console\HelperThe created helper instance.
hr() ¶ public
hr(int $newlines = 0, int $width = 63): voidOutputs a series of minus characters to the standard output, acts as a visual separator.
Parameters
- 
                int$newlines optional
- Number of newlines to pre- and append 
- 
                int$width optional
- Width of the line, defaults to 63 
Returns
voidLinks
in() ¶ public
in(string $prompt, string|array|null $options = null, string|null $default = null): mixedPrompts the user for input, and returns it.
Parameters
- 
                string$prompt
- Prompt text. 
- 
                string|array|null$options optional
- Array or string of options. 
- 
                string|null$default optional
- Default input value. 
Returns
mixedEither the default value, or the user-provided input.
Links
info() ¶ public
info(string|array|null $message = null, int $newlines = 1, int $level = Shell::NORMAL): int|boolConvenience method for out() that wraps message between 
Parameters
- 
                string|array|null$message optional
- A string or an array of strings to output 
- 
                int$newlines optional
- Number of newlines to append 
- 
                int$level optional
- The message's output level, see above. 
Returns
int|boolThe number of bytes returned from writing to stdout.
See Also
initialize() ¶ public
initialize(): voidInitializes the Shell acts as constructor for subclasses allows configuration of tasks prior to shell execution
Returns
voidLinks
io() ¶ public
io(Cake\Console\ConsoleIo|null $io = null): Cake\Console\ConsoleIoGet/Set the io object for this shell.
Parameters
- 
                Cake\Console\ConsoleIo|null$io optional
- The ConsoleIo object to use. 
Returns
Cake\Console\ConsoleIoThe current ConsoleIo object.
loadModel() ¶ public
loadModel(string|null $modelClass = null, string|null $modelType = null): Cake\Datasource\RepositoryInterfaceLoads and constructs repository objects required by this object
Typically used to load ORM Table objects as required. Can also be used to load other types of repository objects your application uses.
If a repository provider does not return an object a MissingModelException will be thrown.
Parameters
- 
                string|null$modelClass optional
- Name of model class to load. Defaults to $this->modelClass 
- 
                string|null$modelType optional
- The type of repository to load. Defaults to the modelType() value. 
Returns
Cake\Datasource\RepositoryInterfaceThe model instance created.
Throws
Cake\Datasource\Exception\MissingModelExceptionIf the model class cannot be found.
InvalidArgumentExceptionWhen using a type that has not been registered.
UnexpectedValueExceptionIf no model type has been defined
log() ¶ public
log(mixed $msg, int|string $level = LogLevel::ERROR, string|array $context = []): boolConvenience method to write a message to Log. See Log::write() for more information on writing to logs.
Parameters
- 
                mixed$msg
- Log message. 
- 
                int|string$level optional
- Error level. 
- 
                string|array$context optional
- Additional log data relevant to this message. 
Returns
boolSuccess of log write.
modelFactory() ¶ public
modelFactory(string $type, callable $factory): voidOverride a existing callable to generate repositories of a given type.
Parameters
- 
                string$type
- The name of the repository type the factory function is for. 
- 
                callable$factory
- The factory function used to create instances. 
Returns
voidmodelType() ¶ public
modelType(string|null $modelType = null): string|$thisSet or get the model type to be used by this class
Parameters
- 
                string|null$modelType optional
- The model type or null to retrieve the current 
Returns
string|$thisnl() ¶ public
nl(int $multiplier = 1): stringReturns a single or multiple linefeeds sequences.
Parameters
- 
                int$multiplier optional
- Number of times the linefeed sequence should be repeated 
Returns
stringLinks
out() ¶ public
out(string|array|null $message = null, int $newlines = 1, int $level = Shell::NORMAL): int|boolOutputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.
Output levels
There are 3 built-in output level. Shell::QUIET, Shell::NORMAL, Shell::VERBOSE.
The verbose and quiet output levels, map to the verbose and quiet output switches
present in most shells. Using Shell::QUIET for a message means it will always display.
While using Shell::VERBOSE means it will only display when verbose output is toggled.
Parameters
- 
                string|array|null$message optional
- A string or an array of strings to output 
- 
                int$newlines optional
- Number of newlines to append 
- 
                int$level optional
- The message's output level, see above. 
Returns
int|boolThe number of bytes returned from writing to stdout.
Links
param() ¶ public
param(string $name): string|bool|nullSafely access the values in $this->params.
Parameters
- 
                string$name
- The name of the parameter to get. 
Returns
string|bool|nullValue. Will return null if it doesn't exist.
parseDispatchArguments() ¶ public
parseDispatchArguments(array $args): arrayParses the arguments for the dispatchShell() method.
Parameters
- 
                array$args
- Arguments fetch from the dispatchShell() method with func_get_args() 
Returns
arrayFirst value has to be an array of the command arguments. Second value has to be an array of extra parameter to pass on to the dispatcher
quiet() ¶ public
quiet(string|array $message, int $newlines = 1): int|boolOutput at all levels.
Parameters
- 
                string|array$message
- A string or an array of strings to output 
- 
                int$newlines optional
- Number of newlines to append 
Returns
int|boolThe number of bytes returned from writing to stdout.
runCommand() ¶ public
runCommand(array $argv, bool $autoMethod = false, array $extra = []): int|bool|nullRuns the Shell with the provided argv.
Delegates calls to Tasks and resolves methods inside the class. Commands are looked up with the following order:
- Method on the shell.
- Matching task name.
- main()method.
If a shell implements a main() method, all missing method calls will be sent to
main() with the original method name in the argv.
For tasks to be invoked they must be exposed as subcommands. If you define any subcommands, you must define all the subcommands your shell needs, whether they be methods on this class or methods on tasks.
Parameters
- 
                array$argv
- Array of arguments to run the shell with. This array should be missing the shell name. 
- 
                bool$autoMethod optional
- Set to true to allow any public method to be called even if it was not defined as a subcommand. This is used by ShellDispatcher to make building simple shells easy. 
- 
                array$extra optional
- Extra parameters that you can manually pass to the Shell to be dispatched. Built-in extra parameter is : - requested: if used, will prevent the Shell welcome message to be displayed
 
Returns
int|bool|nullLinks
shortPath() ¶ public
shortPath(string $file): stringMakes absolute file path easier to read
Parameters
- 
                string$file
- Absolute file path 
Returns
stringshort path
Links
startup() ¶ public
startup(): voidStarts up the Shell and displays the welcome message. Allows for checking and configuring prior to command or main execution
Override this method if you want to remove the welcome information, or otherwise modify the pre-command flow.
Returns
voidLinks
success() ¶ public
success(string|array|null $message = null, int $newlines = 1, int $level = Shell::NORMAL): int|boolConvenience method for out() that wraps message between 
Parameters
- 
                string|array|null$message optional
- A string or an array of strings to output 
- 
                int$newlines optional
- Number of newlines to append 
- 
                int$level optional
- The message's output level, see above. 
Returns
int|boolThe number of bytes returned from writing to stdout.
See Also
tableLocator() ¶ public
tableLocator(Cake\ORM\Locator\LocatorInterface|null $tableLocator = null): Cake\ORM\Locator\LocatorInterfaceSets the table locator. If no parameters are passed, it will return the currently used locator.
Parameters
- 
                Cake\ORM\Locator\LocatorInterface|null$tableLocator optional
- LocatorInterface instance. 
Returns
Cake\ORM\Locator\LocatorInterfaceverbose() ¶ public
verbose(string|array $message, int $newlines = 1): int|boolOutput at the verbose level.
Parameters
- 
                string|array$message
- A string or an array of strings to output 
- 
                int$newlines optional
- Number of newlines to append 
Returns
int|boolThe number of bytes returned from writing to stdout.
warn() ¶ public
warn(string|array|null $message = null, int $newlines = 1): int|boolConvenience method for err() that wraps message between 
Parameters
- 
                string|array|null$message optional
- A string or an array of strings to output 
- 
                int$newlines optional
- Number of newlines to append 
Returns
int|boolThe number of bytes returned from writing to stderr.
See Also
wrapText() ¶ public
wrapText(string $text, int|array $options = []): stringWrap a block of text. Allows you to set the width, and indenting on a block of text.
Options
- widthThe width to wrap to. Defaults to 72
- wordWrapOnly wrap on words breaks (spaces) Defaults to true.
- indentIndent the text with the string provided. Defaults to null.
Parameters
- 
                string$text
- Text the text to format. 
- 
                int|array$options optional
- Array of options to use, or an integer to wrap the text to. 
Returns
stringWrapped / indented text
See Also
Links
Property Detail
$OptionParser ¶ public
An instance of ConsoleOptionParser that has been configured for this class.
Type
Cake\Console\ConsoleOptionParser$Tasks ¶ public
Task Collection for the command, used to create Tasks.
Type
Cake\Console\TaskRegistry$_validationDomain ¶ protected
Holds the validation string domain to use for validation messages when extracting
Type
bool$modelClass ¶ public
This object's primary model class name. Should be a plural form. CakePHP will not inflect the name.
Example: For an object named 'Comments', the modelClass would be 'Comments'.
Plugin classes should use Plugin.Comments style names to correctly load
models from the correct plugin.
Type
string$plugin ¶ public
The name of the plugin the shell belongs to. Is automatically set by ShellDispatcher when a shell is constructed.
Type
string