Class ExtractTask
Language string extractor
- Cake\Console\Shell uses Cake\ORM\Locator\LocatorAwareTrait , Cake\Log\LogTrait , Cake\Utility\MergeVariablesTrait , Cake\Datasource\ModelAwareTrait
-
Cake\Shell\Task\ExtractTask
Inherited Constants
Properties summary
-
$_countMarkerError
protectedCount number of marker errors foundboolean
-
$_exclude
protectedAn array of directories to exclude.array
-
$_extractCore
protectedHolds whether this call should extract the CakePHP Lib messagesboolean
-
$_file
protectedCurrent file being processedstring|null
-
$_files
protectedFiles from where to extractarray
-
$_markerError
protectedDisplays marker error(s) if trueboolean
-
$_merge
protectedMerge all domain strings into the default.pot fileboolean
-
$_output
protectedDestination pathstring|null
-
$_paths
protectedPaths to use when looking for stringsarray
-
$_relativePaths
protectedUse relative paths in the pot files rather than full pathboolean
-
$_storage
protectedContains all content waiting to be writearray
-
$_tokens
protectedExtracted tokensarray
-
$_translations
protectedExtracted strings indexed by domain.array
-
$_validationDomain
protectedHolds the validation string domain to use for validation messages when extractingstring
Inherited Properties
-
OptionParser
,Tasks
,_io
,_taskMap
,args
,command
,interactive
,name
,params
,plugin
,rootName
,taskNames
,tasks
_tableLocator
_modelFactories
,_modelType
,modelClass
Method Summary
- _addTranslation() protectedAdd a translation to the internal translations property
- _buildFiles() protectedBuild the translate template file contents out of obtained strings
- _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() protected
Returns 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
- _parse() protectedParse tokens
- _searchFiles() protectedSearch files that may contain translatable strings
- _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
- getOptionParser() publicGets the option parser instance and configures it.
- main() publicExecution method always used for tasks
Method Detail
_addTranslation()source protected
_addTranslation( string $domain , string $msgid , array $details = [] )
Add 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
_buildFiles()source protected
_buildFiles( )
Build the translate template file contents out of obtained strings
_formatString()source protected
_formatString( string $string )
Format a string to be added as a translatable string
Parameters
- string
$string
- String to format
Returns
stringFormatted string
_getStrings()source protected
_getStrings( integer $position , integer $target )
Get the strings from the position forward
Parameters
- integer
$position
- Actual position on tokens array
- integer
$target
- Number of strings to extract
Returns
arrayStrings extracted
_isExtractingApp()source protected
_isExtractingApp( )
Returns 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
boolean_isPathUsable()source protected
_isPathUsable( string $path )
Checks whether or not a given path is usable for writing.
Parameters
- string
$path
- Path to folder
Returns
booleantrue if it exists and is writable, false otherwise
_markerError()source protected
_markerError( string $file , integer $line , string $marker , integer $count )
Indicate an invalid marker on a processed file
Parameters
- string
$file
- File where invalid marker resides
- integer
$line
- Line number
- string
$marker
- Marker found
- integer
$count
- Count
_parse()source protected
_parse( string $functionName , array $map )
Parse 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)
_store()source protected
_store( string $domain , string $header , string $sentence )
Prepare a file to be stored
Parameters
- string
$domain
- The domain
- string
$header
- The header content.
- string
$sentence
- The sentence to store.
_writeHeader()source protected
_writeHeader( )
Build the translation template header
Returns
stringTranslation template header
getOptionParser()source public
getOptionParser( )
Gets the option parser instance and configures it.
Returns
Cake\Console\ConsoleOptionParser
Overrides
Cake\Console\Shell::getOptionParser()
Methods inherited from Cake\Console\Shell
__construct()source public
__construct( Cake\Console\ConsoleIo $io = null , Cake\ORM\Locator\LocatorInterface $locator = null )
Constructs this Shell instance.
Parameters
-
Cake\Console\ConsoleIo
$io
optional null - An io instance.
-
Cake\ORM\Locator\LocatorInterface
$locator
optional null - Table locator instance.
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#Shell__debugInfo()source public
__debugInfo( )
Returns an array that can be used to describe the internal state of this object.
Returns
array__get()source public
__get( string $name )
Overload get for lazy building of tasks
Parameters
- string
$name
- The task to get.
Returns
Cake\Console\Shell
Object of Task
_displayHelp()source protected
_displayHelp( string $command )
Display the help in the correct format
Parameters
- string
$command
- The command to get help for.
Returns
integer|booleanThe number of bytes returned from writing to stdout.
_setOutputLevel()source protected
_setOutputLevel( )
Set the output level based on the parameters.
This reconfigures both the output level for out() and the configured stdout/stderr logging
_stop()source protected
_stop( integer|string $status = self::CODE_SUCCESS )
Stop execution of the current script. Raises a StopException to try and halt the execution.
Parameters
- integer|string
$status
optional self::CODE_SUCCESS - see https://secure.php.net/exit for values
Throws
Cake\Console\Exception\StopException
_validateTasks()source protected
_validateTasks( )
Checks that the tasks in the task map are actually available
Throws
RuntimeExceptionabort()source public
abort( string $message , integer $exitCode = self::CODE_ERROR )
Displays a formatted error message and exits the application with status code 1
Parameters
- string
$message
- The error message
- integer
$exitCode
optional self::CODE_ERROR - The exit code for the shell task.
Throws
Cake\Console\Exception\StopException
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#styling-outputclear()source public
clear( )
Clear the console
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#console-outputcreateFile()source public
createFile( string $path , string $contents )
Creates a file at given path
Parameters
- string
$path
- Where to put the file.
- string
$contents
- Content to put in the file.
Returns
booleanSuccess
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#creating-filesdispatchShell()source public
dispatchShell( )
Dispatch 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: - command
can accept either a string or an array. Represents the command to dispatch - extra
can accept an array of extra parameters to pass on to the dispatcher. This parameters will be available in the param
property 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
integerThe cli command exit code. 0 is success.
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#invoking-other-shells-from-your-shellerr()source public
err( string|array|null $message = null , integer $newlines = 1 )
Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
Parameters
- string|array|null
$message
optional null - A string or an array of strings to output
- integer
$newlines
optional 1 - Number of newlines to append
Returns
integer|booleanThe number of bytes returned from writing to stderr.
error()source public deprecated
error( string $title , string|null $message = null , integer $exitCode = self::CODE_ERROR )
Displays a formatted error message and exits the application with status code 1
Deprecated
3.2.0 Use Shell::abort() instead.Parameters
- string
$title
- Title of the error
- string|null
$message
optional null - An optional error message
- integer
$exitCode
optional self::CODE_ERROR - The exit code for the shell task.
Returns
integerError code
Throws
Cake\Console\Exception\StopException
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#styling-outputgetIo()source public
getIo( )
Get the io object for this shell.
Returns
Cake\Console\ConsoleIo
The current ConsoleIo object.
hasMethod()source public
hasMethod( string $name )
Check to see if this shell has a callable method by the given name.
Parameters
- string
$name
- The method name to check.
Returns
booleanLink
https://book.cakephp.org/3.0/en/console-and-shells.html#shell-taskshasTask()source public
hasTask( string $task )
Check to see if this shell has a task with the provided name.
Parameters
- string
$task
- The task name to check.
Returns
booleanSuccess
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#shell-taskshelper()source public
helper( string $name , array $settings = [] )
Render 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\Helper
The created helper instance.
hr()source public
hr( integer $newlines = 0 , integer $width = 63 )
Outputs a series of minus characters to the standard output, acts as a visual separator.
Parameters
- integer
$newlines
optional 0 - Number of newlines to pre- and append
- integer
$width
optional 63 - Width of the line, defaults to 63
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#Shell::hrin()source public
in( string $prompt , string|array|null $options = null , string|null $default = null )
Prompts the user for input, and returns it.
Parameters
- string
$prompt
- Prompt text.
- string|array|null
$options
optional null - Array or string of options.
- string|null
$default
optional null - Default input value.
Returns
mixedEither the default value, or the user-provided input.
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#Shell::ininfo()source public
info( string|array|null $message = null , integer $newlines = 1 , integer $level = Cake\Shell\Task\Shell::NORMAL )
Convenience method for out() that wraps message between tag
Parameters
- string|array|null
$message
optional null - A string or an array of strings to output
- integer
$newlines
optional 1 - Number of newlines to append
- integer
$level
optional Cake\Shell\Task\Shell::NORMAL - The message's output level, see above.
Returns
integer|booleanThe number of bytes returned from writing to stdout.
See
https://book.cakephp.org/3.0/en/console-and-shells.html#Shell::outinitialize()source public
initialize( )
Initializes the Shell acts as constructor for subclasses allows configuration of tasks prior to shell execution
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#Cake\Console\ConsoleOptionParser::initializeio()source public deprecated
io( Cake\Console\ConsoleIo $io = null )
Get/Set the io object for this shell.
Deprecated
3.5.0 Use getIo()/setIo() instead.Parameters
-
Cake\Console\ConsoleIo
$io
optional null - The ConsoleIo object to use.
Returns
Cake\Console\ConsoleIo
The current ConsoleIo object.
nl()source public
nl( integer $multiplier = 1 )
Returns a single or multiple linefeeds sequences.
Parameters
- integer
$multiplier
optional 1 - Number of times the linefeed sequence should be repeated
Returns
stringLink
https://book.cakephp.org/3.0/en/console-and-shells.html#Shell::nlout()source public
out( string|array|null $message = null , integer $newlines = 1 , integer $level = Cake\Shell\Task\Shell::NORMAL )
Outputs 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 null - A string or an array of strings to output
- integer
$newlines
optional 1 - Number of newlines to append
- integer
$level
optional Cake\Shell\Task\Shell::NORMAL - The message's output level, see above.
Returns
integer|booleanThe number of bytes returned from writing to stdout.
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#Shell::outparam()source public
param( string $name )
Safely access the values in $this->params.
Parameters
- string
$name
- The name of the parameter to get.
Returns
string|boolean|nullValue. Will return null if it doesn't exist.
parseDispatchArguments()source public
parseDispatchArguments( array $args )
Parses 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()source public
quiet( string|array $message , integer $newlines = 1 )
Output at all levels.
Parameters
- string|array
$message
- A string or an array of strings to output
- integer
$newlines
optional 1 - Number of newlines to append
Returns
integer|booleanThe number of bytes returned from writing to stdout.
runCommand()source public
runCommand( array $argv , boolean $autoMethod = false , array $extra = [] )
Runs 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.
- boolean
$autoMethod
optional false 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
integer|boolean|nullLink
https://book.cakephp.org/3.0/en/console-and-shells.html#the-cakephp-consolesetIo()source public
setIo( Cake\Console\ConsoleIo $io )
Set the io object for this shell.
Parameters
-
Cake\Console\ConsoleIo
$io
- The ConsoleIo object to use.
setRootName()source public
setRootName( string $name )
Set the root command name for help output.
Parameters
- string
$name
- The name of the root command.
Returns
$this
shortPath()source public
shortPath( string $file )
Makes absolute file path easier to read
Parameters
- string
$file
- Absolute file path
Returns
stringshort path
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#Shell::shortPathstartup()source public
startup( )
Starts 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.
Link
https://book.cakephp.org/3.0/en/console-and-shells.html#Cake\Console\ConsoleOptionParser::startupsuccess()source public
success( string|array|null $message = null , integer $newlines = 1 , integer $level = Cake\Shell\Task\Shell::NORMAL )
Convenience method for out() that wraps message between tag
Parameters
- string|array|null
$message
optional null - A string or an array of strings to output
- integer
$newlines
optional 1 - Number of newlines to append
- integer
$level
optional Cake\Shell\Task\Shell::NORMAL - The message's output level, see above.
Returns
integer|booleanThe number of bytes returned from writing to stdout.
See
https://book.cakephp.org/3.0/en/console-and-shells.html#Shell::outverbose()source public
verbose( string|array $message , integer $newlines = 1 )
Output at the verbose level.
Parameters
- string|array
$message
- A string or an array of strings to output
- integer
$newlines
optional 1 - Number of newlines to append
Returns
integer|booleanThe number of bytes returned from writing to stdout.
warn()source public
warn( string|array|null $message = null , integer $newlines = 1 )
Convenience method for err() that wraps message between tag
Parameters
- string|array|null
$message
optional null - A string or an array of strings to output
- integer
$newlines
optional 1 - Number of newlines to append
Returns
integer|booleanThe number of bytes returned from writing to stderr.
See
https://book.cakephp.org/3.0/en/console-and-shells.html#Shell::errwrapMessageWithType()source protected deprecated
wrapMessageWithType( string $messageType , string|array $message )
Wraps a message with a given message type, e.g.
Deprecated
3.6.0 Will be removed in 4.0.0 as it is no longer in use.Parameters
- string
$messageType
- The message type, e.g. "warning".
- string|array
$message
- The message to wrap.
Returns
array|stringThe message wrapped with the given message type.
wrapText()source public
wrapText( string $text , integer|array $options = [] )
Wrap a block of text. Allows you to set the width, and indenting on a block of text.
Options
-
width
The width to wrap to. Defaults to 72 -
wordWrap
Only wrap on words breaks (spaces) Defaults to true. -
indent
Indent the text with the string provided. Defaults to null.
Parameters
- string
$text
- Text the text to format.
- integer|array
$options
optional [] - Array of options to use, or an integer to wrap the text to.
Returns
stringWrapped / indented text
See
\Cake\Utility\Text::wrap()Link
https://book.cakephp.org/3.0/en/console-and-shells.html#Shell::wrapTextMethods used from Cake\ORM\Locator\LocatorAwareTrait
getTableLocator()source public
getTableLocator( )
Gets the table locator.
Returns
Cake\ORM\Locator\LocatorInterface
setTableLocator()source public
setTableLocator( Cake\ORM\Locator\LocatorInterface $tableLocator )
Sets the table locator.
Parameters
-
Cake\ORM\Locator\LocatorInterface
$tableLocator
- LocatorInterface instance.
Returns
$this
tableLocator()source public deprecated
tableLocator( Cake\ORM\Locator\LocatorInterface $tableLocator = null )
Sets the table locator. If no parameters are passed, it will return the currently used locator.
Deprecated
3.5.0 Use getTableLocator()/setTableLocator() instead.Parameters
-
Cake\ORM\Locator\LocatorInterface
$tableLocator
optional null - LocatorInterface instance.
Returns
Cake\ORM\Locator\LocatorInterface
Methods used from Cake\Log\LogTrait
log()source public
log( mixed $msg , integer|string $level = LogLevel::ERROR , string|array $context = [] )
Convenience method to write a message to Log. See Log::write() for more information on writing to logs.
Parameters
- mixed
$msg
- Log message.
- integer|string
$level
optional LogLevel::ERROR - Error level.
- string|array
$context
optional [] - Additional log data relevant to this message.
Returns
booleanSuccess of log write.
Methods used from Cake\Utility\MergeVariablesTrait
_mergeProperty()source protected
_mergeProperty( string $property , array $parentClasses , array $options )
Merge 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()
_mergePropertyData()source protected
_mergePropertyData( array $current , array $parent , boolean $isAssoc )
Merge each of the keys in a property together.
Parameters
- array
$current
- The current merged value.
- array
$parent
- The parent class' value.
- boolean
$isAssoc
- Whether or not the merging should be done in associative mode.
Returns
mixedThe updated value.
_mergeVars()source protected
_mergeVars( array $properties , array $options = [] )
Merge 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.
Methods used from Cake\Datasource\ModelAwareTrait
_setModelClass()source protected
_setModelClass( string $name )
Set the modelClass and modelKey properties based on conventions.
If the properties are already set they will not be overwritten
Parameters
- string
$name
- Class name.
getModelType()source public
getModelType( )
Get the model type to be used by this class
Returns
stringloadModel()source public
loadModel( string|null $modelClass = null , string|null $modelType = null )
Loads 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 null - Name of model class to load. Defaults to $this->modelClass
- string|null
$modelType
optional null - The type of repository to load. Defaults to the modelType() value.
Returns
Cake\Datasource\RepositoryInterface
The model instance created.
Throws
Cake\Datasource\Exception\MissingModelException
If the model class cannot be found.
InvalidArgumentException
When using a type that has not been registered.
UnexpectedValueException
If no model type has been defined
modelFactory()source public
modelFactory( string $type , callable $factory )
Override 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.
modelType()source public deprecated
modelType( string|null $modelType = null )
Set or get the model type to be used by this class
Deprecated
3.5.0 Use getModelType()/setModelType() instead.Parameters
- string|null
$modelType
optional null - The model type or null to retrieve the current
Returns
string|Cake\Datasource\ModelAwareTrait
$this
setModelType()source public
setModelType( string $modelType )
Set the model type to be used by this class
Parameters
- string
$modelType
- The model type
Returns
$this
Magic methods inherited from Cake\Console\Shell
main() |
Properties detail
$_extractCoresource
protected boolean
Holds whether this call should extract the CakePHP Lib messages
false
$_relativePathssource
protected boolean
Use relative paths in the pot files rather than full path
false
$_validationDomainsource
protected string
Holds the validation string domain to use for validation messages when extracting
'default'
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.7/class-Cake.Shell.Task.ExtractTask.html