Documentation

PhpExtractor extends AbstractFileExtractor
in package
implements ExtractorInterface

PhpExtractor extracts translation messages from a PHP template.

Tags
author

Michel Salib michelsalib@hotmail.com

Table of Contents

Interfaces

ExtractorInterface
Extracts translation messages from a directory or files to the catalogue.

Constants

DOMAIN_TOKEN  = 1001
MESSAGE_TOKEN  = 300
METHOD_ARGUMENTS_TOKEN  = 1000

Properties

$sequences  : mixed
The sequence that captures translation messages.
$prefix  : string
Prefix for new found message.

Methods

extract()  : mixed
Extracts translation messages from files, a file or a directory to the catalogue.
setPrefix()  : mixed
Sets the prefix that should be used for new found messages.
canBeExtracted()  : bool
extractFiles()  : iterable<string|int, mixed>
extractFromDirectory()  : iterable<string|int, mixed>
isFile()  : bool
normalizeToken()  : string|null
Normalizes a token.
parseTokens()  : mixed
Extracts trans message from PHP tokens.
getValue()  : mixed
Extracts the message from the iterator while the tokens match allowed message tokens.
seekToNextRelevantToken()  : mixed
Seeks to a non-whitespace token.
skipMethodArgument()  : mixed
toSplFileInfo()  : SplFileInfo

Constants

METHOD_ARGUMENTS_TOKEN

public mixed METHOD_ARGUMENTS_TOKEN = 1000

Properties

$sequences

The sequence that captures translation messages.

protected mixed $sequences = [['->', 'trans', '(', self::MESSAGE_TOKEN, ',', self::METHOD_ARGUMENTS_TOKEN, ',', self::DOMAIN_TOKEN], ['->', 'trans', '(', self::MESSAGE_TOKEN], ['new', 'TranslatableMessage', '(', self::MESSAGE_TOKEN, ',', self::METHOD_ARGUMENTS_TOKEN, ',', self::DOMAIN_TOKEN], ['new', 'TranslatableMessage', '(', self::MESSAGE_TOKEN], ['new', '\\', 'Symfony', '\\', 'Component', '\\', 'Translation', '\\', 'TranslatableMessage', '(', self::MESSAGE_TOKEN, ',', self::METHOD_ARGUMENTS_TOKEN, ',', self::DOMAIN_TOKEN], ['new', '\\Symfony\\Component\\Translation\\TranslatableMessage', '(', self::MESSAGE_TOKEN, ',', self::METHOD_ARGUMENTS_TOKEN, ',', self::DOMAIN_TOKEN], ['new', '\\', 'Symfony', '\\', 'Component', '\\', 'Translation', '\\', 'TranslatableMessage', '(', self::MESSAGE_TOKEN], ['new', '\\Symfony\\Component\\Translation\\TranslatableMessage', '(', self::MESSAGE_TOKEN], ['t', '(', self::MESSAGE_TOKEN, ',', self::METHOD_ARGUMENTS_TOKEN, ',', self::DOMAIN_TOKEN], ['t', '(', self::MESSAGE_TOKEN]]

$prefix

Prefix for new found message.

private string $prefix = ''

Methods

extract()

Extracts translation messages from files, a file or a directory to the catalogue.

public extract(string|iterable<string|int, mixed> $resource, MessageCatalogue $catalog) : mixed
Parameters
$resource : string|iterable<string|int, mixed>

Files, a file or a directory

$catalog : MessageCatalogue

setPrefix()

Sets the prefix that should be used for new found messages.

public setPrefix(string $prefix) : mixed
Parameters
$prefix : string

canBeExtracted()

protected canBeExtracted(string $file) : bool
Parameters
$file : string
Tags
throws
InvalidArgumentException
Return values
bool

extractFiles()

protected extractFiles(string|iterable<string|int, mixed> $resource) : iterable<string|int, mixed>
Parameters
$resource : string|iterable<string|int, mixed>
Return values
iterable<string|int, mixed>

extractFromDirectory()

protected extractFromDirectory(string|array<string|int, mixed> $directory) : iterable<string|int, mixed>
Parameters
$directory : string|array<string|int, mixed>
Return values
iterable<string|int, mixed>

normalizeToken()

Normalizes a token.

protected normalizeToken(mixed $token) : string|null
Parameters
$token : mixed
Return values
string|null

parseTokens()

Extracts trans message from PHP tokens.

protected parseTokens(array<string|int, mixed> $tokens, MessageCatalogue $catalog, string $filename) : mixed
Parameters
$tokens : array<string|int, mixed>
$catalog : MessageCatalogue
$filename : string

getValue()

Extracts the message from the iterator while the tokens match allowed message tokens.

private getValue(Iterator $tokenIterator) : mixed
Parameters
$tokenIterator : Iterator

seekToNextRelevantToken()

Seeks to a non-whitespace token.

private seekToNextRelevantToken(Iterator $tokenIterator) : mixed
Parameters
$tokenIterator : Iterator

skipMethodArgument()

private skipMethodArgument(Iterator $tokenIterator) : mixed
Parameters
$tokenIterator : Iterator

toSplFileInfo()

private toSplFileInfo(string $file) : SplFileInfo
Parameters
$file : string
Return values
SplFileInfo

        
On this page

Search results